2010-08-02 82 views
0

我想在单个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 

    } 

} 

你能帮我请。

+0

您能否显示您的“cellForRowAtIndexPath”方法? – 2010-08-02 10:49:44

+0

它可能不会影响它,但请尝试使用“return [[appDelegate.array_presets] count];”。 – 2010-08-02 10:50:43

+0

这不起作用詹姆斯,多亏了...... – awlcs 2010-08-02 14:11:37

回答

2

我希望我在这里没有误解你,但是。

为什么不为每个UITableView指定一个不同的委托?我假设你在使用“radios_tv.delegate = self”时也使用“presets_tv.delegate = self”。

您必须使用不同的实际委托对象。也许你可以从NSObject创建一个符合UITableViewProtocol的新类,在你的视图控制器中实例化它们,并在创建表视图时分别将它们分配为委托。

+0

不,我不使用“radios_tv.delegate = self”或“presets_tv.delegate = self”。其实我不知道这是什么意思。我是一个新手:p – awlcs 2010-08-02 14:20:14

+0

他说的是你应该创建两个新类(它们是常规的NSObject类),然后将其中一个设置为表视图的代表,另一个是代表其他。 – Kalle 2010-08-02 17:15:28