【发布时间】:2015-05-31 07:55:05
【问题描述】:
我想在 IOS 目标 c 中从数组 Start data 加载到 End data 和再次 Start data 时重复数据。我已经实现了以下代码。我已经使用@try { } @catch 处理异常并停止从index 0 beyond bounds for empty array error 崩溃,但我想实现一些更好的方法
@interface CategoryVC ()
{
NSArray* GradientColour;
}
- (void)viewDidLoad {
[super viewDidLoad];
/*Gradient Colours*/
GradientColour = @[CategoryEntertainmen2,CategoryGroceries2,CategoryAutomobile, CategoryClothing
, CategoryComputer,Categoryeducation,CategoryElectronics,CategoryEntertainment,CategoryGroceries,CategoryHealthButy,CategoryHome,CategoryResturant,CategoryToys,CategoryEntertainmen2,
CategoryGroceries2,CategoryHealthButy2,CategoryHome2,CategoryResturant2,CategoryToys2,CategoryFlowers,CategoryBreakfast,
CategorySpicyFood,CategoryFuriture
];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
/*Gradient Colours*/
if (indexPath.row <23)
{
[cell setImage:[UIImage imageNamed:@"Grass"] andColor:[ GradientColour objectAtIndex:indexPath.row]];
}else{
@try {
[cell setImage:[UIImage imageNamed:@"Grass"] andColor:[ GradientColour objectAtIndex:indexPath.row-23]];
} @catch (id theException) {
/*Handell Crash Conditions*/
[cell setImage:[UIImage imageNamed:@"Grass"] andColor:[ GradientColour objectAtIndex:5]];
}
}
return cell;
}
【问题讨论】:
标签: ios objective-c arrays uitableview indexoutofboundsexception