【发布时间】:2009-09-12 22:57:19
【问题描述】:
我需要在一个 UIView 上有两个 UITableView。我可以让它与一个一起工作,这是代码:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [contentOne count]; // sets row count to number of items in array
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
NSString *firstValue = [[NSString alloc] initWithFormat: @"Row %i% %", indexPath.row+1 ];
NSString *secondValue = [contentOne objectAtIndex:indexPath.row];
NSString *cellValue = [firstValue stringByAppendingString: secondValue]; // appends two strings
[cell.textLabel setText:cellValue];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
我尝试了几种不同的方法。任何人?如果我可以为每个 UITableView 命名一个不同的名称,应该这样做,但它不会让我将 tableView 编辑为任何其他内容而不会崩溃。
【问题讨论】:
-
重复问题尝试以下解决方案:stackoverflow.com/a/11789681/846372
标签: iphone uitableview