iphone – 使用Objective-C iOS以编程方式创建表格

iphone – 使用Objective-C iOS以编程方式创建表格,第1张

概述我是开发iOS应用程序和Objective C本身的新手,所以我有一个很简单的问题. 目前我有一个从工具栏按钮中调用的以下方法.该方法旨在在帧变量fr中创建一个表视图. - (IBAction)addGolfer:(id)sender { CGRect fr = CGRectMake(101, 45, 100, 416); UITableView *tabrleView = [[ 我是开发iOS应用程序和Objective C本身的新手,所以我有一个很简单的问题.

目前我有一个从工具栏按钮中调用的以下方法.该方法旨在在帧变量fr中创建一个表视图.

- (IBAction)addGolfer:(ID)sender {    CGRect fr = CGRectMake(101,45,100,416);    UItableVIEw *tabrleVIEw = [[UItableVIEw alloc]      initWithFrame:fr      style:UItableVIEwStylePlain];    tabrleVIEw.autoresizingMask =      UIVIEwautoresizingFlexibleHeight |      UIVIEwautoresizingFlexibleWIDth;    tabrleVIEw.delegate = self;    tabrleVIEw.dataSource = self;    [tabrleVIEw reloadData];    self.vIEw = tableVIEw;}

调用这个方法的结果不是我所期望的.表格视图不是在框架“fr”中创建表视图,而是填满整个屏幕.

再次,我完全是新的,会感谢任何答案和任何建议.谢谢!

解决方法 当您为UItableVIEw设置dataSource和委托属性时,这意味着,至少必须为dataSource写入此方法:

- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath;- (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section;

如果你不这样做,它将会崩溃.总结你会得到这个(这段代码可能包含语法或逻辑错误 – 我写在记事本):

@interface YourVIEwController : UIVIEwController <UItableVIEwDataSource,UItableVIEwDelegate> {    UItableVIEw *firsttableVIEw;    UItableVIEw *secondtableVIEw;}@end

//

@implementation YourVIEwController#pragma mark - Objects Processing- (voID)addGolfer:(UIbarbuttonItem *)sender {    if (secondtableVIEw) {        [secondtableVIEw removeFromSuperVIEw];        secondtableVIEw = nil;    }    secondtableVIEw = [[UItableVIEw alloc] initWithFrame:CGRectMake(101,416)];    secondtableVIEw.autoresizingMask = UIVIEwautoresizingFlexibleHeight | UIVIEwautoresizingFlexibleWIDth;    secondtableVIEw.delegate = self;    tabrleVIEw.dataSource = self;    [self.vIEw addSubvIEw:secondtableVIEw];}#pragma mark - tableVIEw DataSource Implementation- (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section {    if (tableVIEw == firsttableVIEw) { // your tableVIEw you had before        return 20; // or other number,that you want    }    else if (tableVIEw == secondtableVIEw) {        return 15; // or other number,that you want    }}- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath {    static Nsstring *cellIDentifIEr = @"Cell";    UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:cellIDentifIEr];    if (cell == nil)        cell = [[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleDefault reuseIDentifIEr:cellIDentifIEr];    cell.backgroundVIEw = [[UIVIEw alloc] init];    [cell.backgroundVIEw setBackgroundcolor:[UIcolor clearcolor]];    [[[cell contentVIEw] subvIEws] makeObjectsPerformSelector:@selector(removeFromSupervIEw)];    if (tableVIEw == firsttableVIEw) { // your tableVIEw you had before        // ...    }    else if (tableVIEw == secondtableVIEw) {        cell.TitleLabel.text = [Nsstring stringWithFormat:@"Cell %d",indexPath.row + 1];    }    return cell;}@end
总结

以上是内存溢出为你收集整理的iphone – 使用Objective-C iOS以编程方式创建表格全部内容,希望文章能够帮你解决iphone – 使用Objective-C iOS以编程方式创建表格所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1063210.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存