0

I added a new TableView in my application. I changed the cell-type to static and dragged some labels into the cells. Now i want to access the cells programmatically. For example: Cell 4 in Section 3 should open safari with google.com.

I created a new UITableViewController-class. Then i changed the number of sections to 3, and added a switch/case statement to the the numberofcellsinsection method.

If i run the app and open up the table view, the app crashes. Can someone help me, with setting up the TableView ?

Thanks!

EDIT

Here is the log

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
*** First throw call stack:
Mike_NotGuilty
  • 2,253
  • 5
  • 32
  • 64
  • Post the crash log please. – Adrian P Nov 24 '13 at 14:33
  • To access different cells separately you may need to use different identifiers for that purpose. Try a if or switch statement in your cell for row to access the different cells. Check out this link for better understanding of how it is done...http://stackoverflow.com/questions/14303832/uitableview-with-two-custom-cell-multiple-identifier – Adrian P Nov 24 '13 at 14:38
  • I don't have any identifiers because im using static cells. Do i have to change something in the cellForRowAtIndexPath method? – Mike_NotGuilty Nov 24 '13 at 14:40
  • You shouldn't be implementing any of the data source methods when you use static cells. You should read the "Populating a Static Table View With Data" section of the "Table View Programming Guide for iOS". – rdelmar Nov 24 '13 at 15:30

1 Answers1

0

I found a solution which is working.

i edited the cellForRowAtIndexPath method like this:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];

    return cell;
}

Now i can access my static cells with the if statements for example:

    -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 2){

    if (indexPath.row == 1){

            NSLog(@"Tap");

            [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://www.google.com"]];       
          }
    }        
 }
Mike_NotGuilty
  • 2,253
  • 5
  • 32
  • 64