如何在IOS objective c中重复从阵列开始数据到结束数据以及再次开始数据的数据
我想在从数组如何在IOS objective c中重复从阵列开始数据到结束数据以及再次开始数据的数据,ios,objective-c,arrays,uitableview,indexoutofboundsexception,Ios,Objective C,Arrays,Uitableview,Indexoutofboundsexception,我想在从数组开始数据加载到结束数据时重复数据,然后在IOS目标c中再次加载开始数据。我已经实现了以下代码。我使用了@try{}@catch来处理异常,并停止从索引0崩溃,超出空数组错误的界限,但我想实现一些更好的方法 @interface CategoryVC () { NSArray* GradientColour; } - (void)viewDidLoad { [super viewDidLoad]; /*Gradient Colours*/ Grad
开始数据
加载到结束数据
时重复数据,然后在IOS目标c中再次加载开始数据
。我已经实现了以下代码。我使用了@try{}@catch
来处理异常,并停止从索引0崩溃,超出空数组错误的界限
,但我想实现一些更好的方法
@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;
}
@interface CategoryVC()
{
NSArray*渐变色;
}
-(无效)viewDidLoad{
[超级视图下载];
/*渐变色*/
GradientColor=@[CategoryIntertain2,CategoryRoceries2,CategoryAutomobile,CategoryCyclothing
,类别计算机,类别教育,类别电子,类别娱乐,类别电脑,类别健康,类别家庭,类别娱乐,类别娱乐,
类别2、类别2、类别2、类别2、类别2、类别2、类别2、类别2、类别3,
分类食品
];
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
/*渐变色*/
如果(indexPath.row如果我正确理解了您的意图,那么有一个特定的操作用于您想要的内容,它被称为。您可以使用一行代码来完成它:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//Set up cell
NSUInteger index = indexPath.row % GradidentColour.count;
[cell setImage:[UIImage imageNamed:@"Grass"] andColor:[GradientColour objectAtIndex:index]];
return cell;
}
%
操作符从indepath.row
除以23中查找提醒。您可以通过使用数据源数组的计数替换硬编码的23来进一步调整它。我想在从数组开始数据到结束数据加载时重复数据,再次从开始数据到结束数据重复启动数据到结束数据重复启动数据到结束数据我知道是什么目前我所做的不是一个好方法,所以我在寻找答案。你有没有理解我的意思questions@nischalhada这段代码正是这样做的。您可以尝试这段代码,不要忘记设置大量的行。@nischalhada我按照我的理解回答了您的问题。请尝试这段代码,如果它不能解决您的问题,请澄清你的问题。