Я разрабатываю приложение панели вкладок, и каждая вкладка представляет собой табличное представление.Так что моя проблема в том, что на первой вкладке я разработал простое табличное представление, но на второй мне нужен сгруппированный.Я изменил стиль в xib на сгруппированный и в методе сделал это:
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
}
return self;
}
Но симулятор все еще показывает мне простое табличное представление.Когда я пытался написать тот же код в новом приложении - все работало нормально.Может кто-нибудь помочь и объяснить, почему это не работает?
Весь код:
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *row1 = [[NSArray alloc] initWithObjects:@"aaa1", @"aaa2", @"aaa3", nil];
NSArray *row2 = [[NSArray alloc] initWithObjects:@"bbb1", @"bbb2", @"bbb3", nil];
NSArray *row3 = [[NSArray alloc] initWithObjects:@"ccc1", @"ccc2", @"ccc3", nil];
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:
row1, @"a",
row2, @"b",
row3, @"c", nil];
self.list = dict;
NSArray *array = [[list allKeys] sortedArrayUsingSelector:@selector(compare:)];
self.keys = array;
[row1 release];
[row2 release];
[row3 release];
[dict release];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSString *key = [keys objectAtIndex:section];
NSArray *nameSection = [list objectForKey:key];
return [nameSection count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
NSString *key = [self.keys objectAtIndex:section];
NSArray *nameSection = [self.list objectForKey:key];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [nameSection objectAtIndex:row];
return cell;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSString *key = [self.keys objectAtIndex:section];
return key;
}
На самом деле ничего, что я изменить в инспекторе атрибутов в файле XIB, похоже, не работает.кто-нибудь может помочь?