最近开发UITableView调用自定义的UITableViewCell的方式适用于低版本

来源:互联网 发布:et网络运动会管理系统 编辑:程序博客网 时间:2024/06/08 14:36

下面的内容主要:

当自定义了一个UITableViewCell后,如何加载的问题。最好适用于低版本,这个代码适用于低版本的解决办法,之前

的办法只能适用于ios5以上版本。但是下面的代码能够适应低版本问题。

这个是再主TableView的类中的,调用cellForRowAtIndexPath,加载每一行的数据内容。每一行都是一个UITableViewCell

主要参考了这篇http://blog.csdn.net/xiaoquanhuang/article/details/6856688文章来实现我的功能。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CustomCellIdentifier = @"CustomCellIdentifier";

    DiscountProductCell * cell=  (DiscountProductCell*)[tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier];

    if (cell == nil) {

        NSArray * nib = [[NSBundle mainBundleloadNibNamed:@"DiscountProductCell" owner:self options:nil] ;

        cell = [nib objectAtIndex:0];

    }

    PushItm * mPushItem = [mPushItems objectAtIndex:indexPath.row];

    NSLog(@"mPushItem 放在了加载cell里面:%@",mPushItem);

    NSLog(@"mPushItem.type-%d",mPushItem.type);

    NSLog(@"mPushItem.desc-%@",mPushItem.desc);

    NSLog(@"mPushItem.isRead-%@",mPushItem.isRead?@"YES":@"NO");

    NSLog(@"mPushItem.itemId-%@",mPushItem.itemId);

    NSLog(@"mPushItem.title-%@",mPushItem.title);

 http://blog.csdn.net/xiaoquanhuang/article/details/6856688

    cell.item = mPushItem;

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    UIImageView *backgroundView = [[[UIImageView allocinitWithImage:[UIImage imageNamed:@"list"]] autorelease];

    cell.backgroundView = backgroundView;

    UIImageView *accessoryView = [[[UIImageView allocinitWithImage:[UIImage imageNamed:@"ad1"]] autorelease];

    [accessoryView setFrame:CGRectMake(0.0f0.0fCATEGORY_CELL_AC_WIDTHCATEGORY_CELL_AC_HEIGHT)];

    cell.accessoryView = accessoryView;

    return cell;

}

原创粉丝点击