【发布时间】:2012-12-23 08:28:00
【问题描述】:
我有 2 个视图 - view1 和 view2,一个用于输入数据,另一个用于显示输入的数据。 我能够在标签中的 view2 中显示输入的数据。但是如何在 UITableView 中显示数据。以下是我显示数据的代码:
view2.m
@synthesize details; //details is an object of NSMutableArray.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
textLabel.text = self.name;
lblCity.text = self.city;
lblGender.text = self.gender;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [details count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [details objectAtIndex:indexPath.row];
//cell.imageView.image = [UIImage imageNamed:@"creme_brelee.jpg"];
return cell;
我调试后发现cellForRowAtIndexPath 从未被调用过。
我哪里错了?如何解决?
【问题讨论】:
-
您是否将tableView 的
dataSource和delegate设置为您的对象? -
对不起,我是 ios 新手,如何设置它们?
-
如果您在 xib 中使用了表,则将其委托方法设置为文件所有者。看到这个techotopia.com/index.php/…
-
转到您的xib文件并选择您的表格并右键单击表格并将委托和数据源附加到文件所有者
-
@z22 进入Interface Builder,右键点击你的UITableView,你会找到两个出口,
delegate和dataSource。单击小圆圈并将蓝线拖到您的文件所有者/您的对象。
标签: iphone ios uitableview uinavigationcontroller