您的位置:首页 > 产品设计 > UI/UE

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

2014-05-29 01:34 316 查看
几个遗留的问题需要研究,先临时放在这里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:UITableViewCellStyleDefaultreuseIdentifier: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 *)tableViewwillSelectRowAtIndexPath:(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];

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: