Momi Momi - 3 months ago 15
iOS Question

Import 495 Cell to TableView

I want to create a table-view with 495 cells.

I want to import cells with NSArray, is it right way?

If yes, how can create 495 cells with simple code?

Not like this :

@"Cell 1" @ "cell 2" @"cell 3", @"cell 4", @"cell 5" ............. @"cell 495"


you will have to return the value of 495 in the '-tableView:numberOfRowsInSection:' method like

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSLog(@"Returning num rows");
    return 495;

then populating the table with your array

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
NSUInteger row = [indexPath row];
    cell.text = [array objectAtIndex:row];
      return cell;

here i assumed that you are storing text data in the cells. Also create the array in viewDidLoad method.