I have a similar implementation.
Implementation: I created the following methods. (I edited them according to your code.)
-(Homework*) homeworkAtIndex: (NSInteger) index { return [alist objectAtIndex:index] ; } -(NSInteger) numberOfObjectsInList { return [alist count]; }
And in the delegate method of the UITableViewController:
- (NSInteger) tableView: (UITableView*) tableView numberOfRowsInSection: (NSInteger) section
I used this method call
return [self numberOfObjectsInList];
In the delegate method:
- (UITableViewCell*) tableView: (UITableView*) tableView cellForRowAtIndexPath: (NSIndexPath*) indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:SubtitleIdentifier] autorelease]; Homework *ai = [self homeworkAtIndex: indexPath.row]; }
Using the homeworkAtIndex method will allow you to populate the various objects in the array into different cells of the table.
Thus, I was able to create custom cells and format cell sizes to fit the table. Perhaps this may work for you if the data to be displayed is not that long and you really don't need to use custom cells. (As in the example I presented)
If you are interested in how to check if the selected cells are selected (since after that you can click them on another viewController), you can do this in the delegate method:
- (void) tableView: (UITableView*) tableView didSelectRowAtIndexPath: (NSIndexPath*) indexPath { UIViewController* nextViewController = nil; NSString* cellDisplayName = [delegate homeworkAtIndex: indexPath.row].name;
I use NSString here to check the class Name, because I'm not sure what the Homework object is, but you can definitely change the logic to match the Homework object, since in my opinion you can have different objects with the same className.
Hope this helps! :)
source share