2012-05-11 95 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]; 
}