[ios专项]几个遗留问题dequeueReusableCellWithIdentifier_2014-05-29

来源:互联网 发布:英雄联盟 知乎 编辑:程序博客网 时间:2024/06/05 19:44

几个遗留的问题需要研究,先临时放在这里

dequeueReusableCellWithIdentifier


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



   CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier];    if (cell == nil) {         cell = [[CustomCell alloc]                 initWithStyle:UITableViewCellStyleDefault                 reuseIdentifier:CustomCellIdentifier]; 


翻译下面这段代码:

如下是:<pre code_snippet_id="368078" snippet_file_name="blog_20140529_2_5526610" name="code" class="objc">dequeueReusableCellWithIdentifier
的问题
#pragma mark -#pragma mark Table Data Source Methods- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {    return [self.dataList count];}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    static NSString *CustomCellIdentifier = @"CustomCellIdentifier";        static BOOL nibsRegistered = NO;    if (!nibsRegistered) {        UINib *nib = [UINib nibWithNibName:@"CustomCell" bundle:nil];        [tableView registerNib:nib forCellReuseIdentifier:CustomCellIdentifier];        nibsRegistered = YES;    }        CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier];    if (cell == nil) {         cell = [[CustomCell alloc]                 initWithStyle:UITableViewCellStyleDefault                 reuseIdentifier:CustomCellIdentifier];     }         NSUInteger row = [indexPath row];     NSDictionary *rowData = [self.dataList objectAtIndex:row];         cell.name = [rowData objectForKey:@"name"];     cell.dec = [rowData objectForKey:@"dec"];     cell.loc = [rowData objectForKey:@"loc"];     cell.image = [imageList objectAtIndex:row];         return cell;}#pragma mark Table Delegate Methods- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {    return 60.0;}- (NSIndexPath *)tableView:(UITableView *)tableView   willSelectRowAtIndexPath:(NSIndexPath *)indexPath {     return nil;}
如下是:<pre name="code" class="objc">bundle URLForResource的问题
<pre name="code" class="objc">//加载plist文件的数据和图片    NSBundle *bundle = [NSBundle mainBundle];    NSURL *plistURL = [bundle URLForResource:@"friendsInfo" withExtension:@"plist"];        NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfURL:plistURL];        NSMutableArray *tmpDataArray = [[NSMutableArray alloc] init];    NSMutableArray *tmpImageArray = [[NSMutableArray alloc] init];    for (int i=0; i<[dictionary count]; i++) {        NSString *key = [[NSString alloc] initWithFormat:@"%i", i+1];        NSDictionary *tmpDic = [dictionary objectForKey:key];        [tmpDataArray addObject:tmpDic];                NSString *imageUrl = [[NSString alloc] initWithFormat:@"%i.png", i+1];        UIImage *image = [UIImage imageNamed:imageUrl];        [tmpImageArray addObject:image];    }    self.dataList = [tmpDataArray copy];    self.imageList = [tmpImageArray copy];




0 0