2012-05-11 163 views
0

我有一个UITableView,我列出了下面的代码。UITableView将内容拆分成部分

如何区分这些对象,如下所示:

数学
代数
几何
演算

科学
集成1
集成2

下面是代码:

- (void)viewDidLoad { 

    NSArray *array = [[NSArray alloc] initWithObjects:@"Math",@"Science",@"English",@"Social Studies",@"Spanish",@"German",@"French",@"Biology",nil]; 

    self.listData = array; 
    [array release]; 
    [super viewDidLoad]; 
} 

回答

0

在您的UITableView对象的UITableViewDataSource;

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

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    return [array objectAtIndex:section]; 
} 

将为您的情况做'切片'部分。

+0

IM有一个问题它不是还在工作...... - (NSInteger的)的tableView:(UITableView的*)的tableView numberOfRowsInSection:(NSInteger的)部分 { \t回报[self.listData计数] } - (的UITableViewCell *)的tableView:(UITableView的*)的tableView 的cellForRowAtIndexPath:(NSIndexPath *)indexPath { 静态的NSString * SimpleTableIdentifier = @ “SimpleTableIdentifier”; 的UITableViewCell *细胞= [的tableView dequeueReusableCellWithIdentifier: \t \t \t \t \t \t \t SimpleTableIdentifier]; –

0
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return [yourarray count]; 
} 

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    return [yourarray objectAtIndex:section]; 
}