菜鸟教程小白 发表于 2022-12-11 22:40:00

ios - 如何创建具有多行多列的表格 View ?


                                            <p><p>我知道如何创建一个单列多行的tableview,但我不知道如何创建一个多行多列的tableview。</p>

<p>谁能帮帮我?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我就是这样做的:</p>

<pre><code>#import &lt;Foundation/Foundation.h&gt;

@interface MyTableCell : UITableViewCell

{   
NSMutableArray *columns;
}

- (void)addColumn:(CGFloat)position;

@end
</code></pre>

<p>实现:</p>

<pre><code>#import &#34;MyTableCell.h&#34;

#define LINE_WIDTH 0.25

@implementation MyTableCell

- (id)init
{
self = ;
if (self) {
    // Initialization code here.
}

return self;
}

- (void)addColumn:(CGFloat)position
{
];
}

- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
// Use the same color and width as the default cell separator for now
CGContextSetRGBStrokeColor(ctx, 0.5, 0.5, 0.5, 1.0);
CGContextSetLineWidth(ctx, LINE_WIDTH);

for (int i = 0; i &lt; ; i++)
{
    CGFloat f = [((NSNumber*) ) floatValue];
    CGContextMoveToPoint(ctx, f, 0);
    CGContextAddLineToPoint(ctx, f, self.bounds.size.height);
}

CGContextStrokePath(ctx);

;
}

@end
</code></pre>

<p>最后一 block ,cellForRowAtIndexPath</p>

<pre><code>MyTableCell *cell = (MyTableCell *);
cell            = [[ initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何创建具有多行多列的表格 View ?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/10118962/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/10118962/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何创建具有多行多列的表格 View ?