views:

143

answers:

2

Hi everyone

I'm trying to put 2 TableViews on a single UIView. I've implemented the methods needed. I've tested the apps with breakpoints and the project fails at this method.

I have 2 tableviews : radios_tv and presets_tv Two arrays from the delegate from which count is obtained: array_radios and array_presets array_radios contains 10 elements. array_presets contains 30 elements.

I've tested for the part:

if (tableView == self.presets_tv) {
    return appDelegate.array_presets.count; //Contains 30 elements in the array_radios
}

Everything is ok if I put return anything below 10. But the project fails with a SIGABRT error if the return is greater than 10 and in my case, as the array_presets contains 30 elements, it fails.

Below is my code:

    - (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
}
}

Could you help me please. I can't see what is wrong...

Thanks

+1  A: 

I hope I didn't misunderstand you here but.

Why don't you specify a different delegate for every UITableView? I'm assuming you're using something like "radios_tv.delegate = self" when you're also doing "presets_tv.delegate = self".

You'd have to use different actual delegate objects. Maybe you could create a new class from NSObject conforming to the UITableViewProtocol, instantiate them in your view controller and assign them as delegates respectively when creating the table views.

Jonny
no I don't use "radios_tv.delegate = self" nor "presets_tv.delegate = self". In fact I don't know what this means. I'm a newbie :p
okayasu
What he's saying is that you should create two new classes (which are regular NSObject ones) and then set one of them to be the delegate for one of the table views and the other one the delegate for the other.
Kalle
A: 

You were right jasonapple. Here is my 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

    }

}

Can you help me please.

okayasu