我想在单个UIView上放2个TableViews。我已经实现了所需的方法。我已经用断点测试了应用程序,并且此方法失败。多个UITableView在单个UIView
我有2个tableviews:radios_tv和presets_tv 从其中获得计数委托两个数组:array_radios和array_presets array_radios包含10个元素。 array_presets包含30个元素。
我测试过的部分:
if (tableView == self.presets_tv) {
return appDelegate.array_presets.count; //Contains 30 elements in the array_radios
}
一切都OK了,如果我把返回低于10任何东西,但这个项目失败了SIGABRT错误,如果回报率是大于10,在我的情况下,因为array_presets包含30个元素,所以失败。
下面是我的代码:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
MyApplicationAppDelegate *appDelegate = (MyApplicationAppDelegate *)[[UIApplication sharedApplication] delegate];
if (tableView == self.radios_tv){
return appDelegate.array_radios.count; //Contains 10 elements in the array_radios
}
if (tableView == self.presets_tv) {
return appDelegate.array_presets.count; //Contains 30 elements in the array_radios
}
}
这是我cellForAtRowIndex
// Customize the appearance of table view cells.
- (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];
}
// Configure the cell...
// Set up the cell
MyAppAppDelegate *appDelegate = (MyAppAppDelegate *)[[UIApplication sharedApplication] delegate];
if (tableView == radios_tv) { //radio_tv is an IBOutleet UITableView
sqlClass *aRadio = (sqlClass *)[appDelegate.array_radios objectAtIndex:indexPath.row];
[cell setText:aRadio.r_name];
return cell;
}
if (tableView == presets_tv) { //preset_tv is an IBOutlet UITableView
}
}
你能帮我请。
您能否显示您的“cellForRowAtIndexPath”方法? – 2010-08-02 10:49:44
它可能不会影响它,但请尝试使用“return [[appDelegate.array_presets] count];”。 – 2010-08-02 10:50:43
这不起作用詹姆斯,多亏了...... – awlcs 2010-08-02 14:11:37