tableView的一些函數

//返回行數

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

{
    return [listData count];

}

//返回一個cell,即每一行所要顯示的內容

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * identify=@"identify";
    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:identify];
    if(cell==nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identify];
    }
    NSUInteger row = [indexPath row];
    cell.textLabel.text = [listData objectAtIndex:row];
    UIImage *image=[UIImage imageNamed:@"qq.png"];
    cell.imageView.image=image;
    if(row<7)
        cell.detailTextLabel.text = @"Mr . Disney";
    else
        cell.detailTextLabel.text = @"Mr . Tolkien";
    return cell;

}

//設置一個叫indent level的屬性,這樣每一行都比上一行右移一點

-(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger row = [indexPath row];
    return  row;

}

//設置點擊事件前可以設置哪一行不能響應點擊事件

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger row=[indexPath row];
    if(row==0)
    {
        return nil;
    }
    return indexPath;

}

//設置點擊事件

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger row = [indexPath row];
    NSString * rowvalue=[listData objectAtIndex:row];
    NSString * message=[[NSString alloc] initWithFormat:@"你選擇了%@",rowvalue];
    UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"注意!" message:message delegate:nil cancelButtonTitle:@"取消" otherButtonTitles: nil];
    [alert show];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

//設置列寬

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章