无法在 UITableView 中显示文本
我有一个基于视图的应用程序,只做一件事:在 TableView 中显示一个数组,但它不起作用,我不知道为什么。这是代码。
.h
@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>{
NSArray *array;
IBOutlet UITableView *table;
}
.m
-(void)viewDidLoad{
[super viewDidLoad];
array = [array initWithObjects:@"iPad", @"iTV", nil];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [array count];
}
- (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] autorelease];
}
cell.textLabel.text = [array objectAtIndex:indexPath.row];
return cell;
}
有什么想法为什么 TableView 不显示文本吗?谢谢你们!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
还应该
确保您像大麦提到的那样调用 arrayInit
编辑:
文斯正确地指出它应该是
或
取决于您是否想保留或自动释放它
Should be
also make sure you call arrayInit as barley mentioned
edit:
Vince is right in pointing out it should either be
or
depending on if you want to retain or have it auto released
我假设您在 ARC NSIndexPath 下运行
没有“行”属性尝试
Ill assume you are running under ARC
NSIndexPath doesn't have a "row" property try