0

I have a tableview code like this:

my tableview.m file:

@implementation RevealTableViewController {

     NSArray *menuItems;
}

- (void)viewDidLoad {
    [super viewDidLoad];

   menuItems = @[@"CART", @"WISHLIST", @"LOGIN", @"REGISTER", @"NEW ARRIVALS", @"BRANDS", @"CLOTHING", @"ACCESSORIES", @"SHOES",@"CATEGORY 6", @"CATEGORY 7",@"CATEGORY 8",@"CATEGORY 9"];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return menuItems.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [tableView setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [tableView setLayoutMargins:UIEdgeInsetsZero];
    }

    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    return cell;
}

I know how to make a section header by titleForHeaderInSection method in first line, but if I just want to grouping my tableview form @"NEW ARRIVALS" to @"CATEGORY 9"? How can I do?

NorthCat
  • 9,643
  • 16
  • 47
  • 50
Match Tsui
  • 49
  • 8
  • See if this [http://stackoverflow.com/questions/18822619/ios-7-tableview-like-in-settings-app-on-ipad][1] helps you. [1]: http://stackoverflow.com/questions/18822619/ios-7-tableview-like-in-settings-app-on-ipad – swapnilagarwal Mar 27 '15 at 07:16

2 Answers2

0

This method return how many rows in each section,

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

If you want to group your table, implement this method

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;

then customize header in this delegate method:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
Weizhi
  • 174
  • 4
  • 22
0

grouping my tableview form @"NEW ARRIVALS" to @"CATEGORY 9"

You want each item to have its own section right?

1 Section for each item

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    menuItems.count;
}

1 Row for each section

- (NSInteger)tableView:(UITableView *)tableView 
                      numberOfRowsInSection:(NSInteger)section {
    return 1;
}

Menu title for each section

-(NSString *)tableView:(UITableView *)tableView 
                         titleForHeaderInSection:(NSInteger)section{
   return menuItems[section];
}
meda
  • 45,103
  • 14
  • 92
  • 122