Jul*_*anB 3 uitableview ipad ios
iPad:我的桌子表现得很好,直到细胞延伸到可见区域(屏幕高度)之外.部分屏幕外的最后一个单元格向下滚动,使其不再可见,然后向上滚动应用程序崩溃?为什么?
代码重新用于iPhone屏幕,工作正常(这是一个通用的应用程序).被这一个难倒
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"JobCell";
UITableViewCell *cell;
NSArray *versionCompatibility = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
if ( 6 <= [[versionCompatibility objectAtIndex:0] intValue] )
{
// iOS6 is installed
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
}
else
{
// iOS5 is installed
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
}
// Configure the cell...
Job *job = [self.jobs objectAtIndex:indexPath.row];
NSLog(@"Dealing with cell %d",indexPath.row);
UIColor *redcol = [UIColor colorWithRed:0.62745098039216 green:0.15294117647059 blue:0.15686274509804 alpha:1.0];
NSString *jobString = job.jobAddress;
jobString = [jobString stringByAppendingString:@", "];
jobString = [jobString stringByAppendingString:job.jobPostcode];
//cell.textLabel.text = jobString;
NSLog(@"jobString %@",jobString);
UILabel *jobLabel = (UILabel *)[cell.contentView viewWithTag:10];
jobLabel.text = jobString;
int jobsaved = job.jobSaved;
if (jobsaved == 1)
{
//cell.textLabel.textColor = redcol;
jobLabel.textColor = redcol;
}
else
{
//cell.textLabel.textColor = [UIColor blackColor];
jobLabel.textColor = [UIColor blackColor];
}
NSLog(@"date %@",job.jobDate);
UILabel *dateLabel = (UILabel *)[cell.contentView viewWithTag:11];
if (! [job.jobDate isEqualToString:@""]) {
NSDateFormatter *formater = [[NSDateFormatter alloc] init];
[formater setDateFormat:@"yyyy-MM-dd"];
NSDate *date2 = [formater dateFromString:job.jobDate];
[formater setDateFormat:@"d MMM YYYY"];
NSString *date = [formater stringFromDate:date2];
//cell.detailTextLabel.text = date;
dateLabel.text = date;
}
else
{
//cell.detailTextLabel.text = @"";
dateLabel.text = @"";
}
UIButton *mapBtn = (UIButton *)[cell viewWithTag:12];
[mapBtn addTarget:self action:@selector(showMap:) forControlEvents:UIControlEventTouchUpInside];
mapBtn.tag = indexPath.row;
return cell;
}
Run Code Online (Sandbox Code Playgroud)
错误是
-[UIButton setText:]: unrecognized selector sent to instance 0x2aba90
2013-07-04 09:32:48.563 ESC GasCert[3175:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIButton setText:]: unrecognized selector sent to instance 0x2aba90'
*** First throw call stack:
(0x37e208bf 0x3796c1e5 0x37e23acb 0x37e22945 0x37d7d680 0x6e0e3 0x319289cb 0x31927aa9 0x31927233 0x318cbd4b 0x37d7f22b 0x37419381 0x37418f99 0x3741d11b 0x3741ce57 0x374446f1 0x374674c5 0x37467379 0x34b76f93 0x3764e891 0x37de9f43 0x37df4553 0x37df44f5 0x37df3343 0x37d764dd 0x37d763a5 0x37b4dfcd 0x318f6743 0x22f1 0x2278)
terminate called throwing an exception(lldb)
Run Code Online (Sandbox Code Playgroud)
碰撞
0x217a: blx 0xa7ef8 ; symbol stub for: NSStringFromClass
0x217e: mov r7, r7
0x2180: blx 0xa7f8c ; symbol stub for: objc_retainAutoreleasedReturnValue
0x2184: movs r2, #0
0x2186: movt r2, #0
0x218a: ldr r1, [sp, #8]
0x218c: str r0, [sp]
0x218e: mov r0, r1
0x2190: ldr r1, [sp, #4]
0x2192: ldr r3, [sp]
0x2194: blx 0xa7ed8 ; symbol stub for: UIApplicationMain
0x2198: str r0, [sp, #32]
Run Code Online (Sandbox Code Playgroud)
我试过了
.H
@property (nonatomic, copy) NSString *jobString;
Run Code Online (Sandbox Code Playgroud)
.M
_jobString = job.jobAddress;
_jobString = [_jobString stringByAppendingString:@", "];
_jobString = [_jobString stringByAppendingString:job.jobPostcode];
Run Code Online (Sandbox Code Playgroud)
编辑:
这是iPhone故事板的代码,不会崩溃
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"JobCell";
UITableViewCell *cell;
NSArray *versionCompatibility = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
if ( 6 <= [[versionCompatibility objectAtIndex:0] intValue] )
{
// iOS6 is installed
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
}
else
{
// iOS5 is installed
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
}
// Configure the cell...
Job *job = [self.jobs objectAtIndex:indexPath.row];
UIColor *redcol = [UIColor colorWithRed:0.62745098039216 green:0.15294117647059 blue:0.15686274509804 alpha:1.0];
NSString *jobString = job.jobAddress;
jobString = [jobString stringByAppendingString:@", "];
jobString = [jobString stringByAppendingString:job.jobPostcode];
//cell.textLabel.text = jobString;
UILabel *jobLabel = (UILabel *)[cell viewWithTag:10];
jobLabel.text = jobString;
int jobsaved = job.jobSaved;
if (jobsaved == 1)
{
//cell.textLabel.textColor = redcol;
jobLabel.textColor = redcol;
}
else
{
//cell.textLabel.textColor = [UIColor blackColor];
jobLabel.textColor = [UIColor blackColor];
}
NSLog(@"date %@",job.jobDate);
UILabel *dateLabel = (UILabel *)[cell viewWithTag:11];
if (! [job.jobDate isEqualToString:@""]) {
NSDateFormatter *formater = [[NSDateFormatter alloc] init];
[formater setDateFormat:@"yyyy-MM-dd"];
NSDate *date2 = [formater dateFromString:job.jobDate];
[formater setDateFormat:@"d MMM YYYY"];
NSString *date = [formater stringFromDate:date2];
//cell.detailTextLabel.text = date;
dateLabel.text = date;
}
else
{
//cell.detailTextLabel.text = @"";
dateLabel.text = @"";
}
UIButton *mapBtn = (UIButton *)[cell viewWithTag:12];
[mapBtn addTarget:self action:@selector(showMap:) forControlEvents:UIControlEventTouchUpInside];
mapBtn.tag = indexPath.row;
return cell;
}
Run Code Online (Sandbox Code Playgroud)
编辑:
决定整体使用标签方法充满了问题.通过在这篇文章中使用解决方案解决问题检测在UITableView中按下了哪个UIButton
我认为你正在弄乱标签,这就是我所看到的: mapBtn.tag = indexPath.row;你不应该改写tag那样的,因为它UIButton可能是由viewWithTag而不是取而代之UILabel,这就是为什么你得到的[UIButton setText:].
所以你应该找到另一种标记动作的方法.
| 归档时间: |
|
| 查看次数: |
560 次 |
| 最近记录: |