我有一个问题,我的数组未设置为我想要的部分。 在下的代码:部分中的数组问题(TableView)
- (NSInteger的)的tableView:(UITableView的*)的tableView numberOfRowsInSection:(NSInteger的)部分
只有所述第二阵列被设置成部分,但它重复在其自其他2个部分,而不是其他部分的其他部分。我有 - 如果我把一个数组(比方说第三个)多于5行像第一个和第二个数组,它给我错误:终止应用程序由于未捕获的异常'NSRangeException' ,原因: '* - [__ NSArrayM objectAtIndex:]:指数5超出范围[0 .. 4]'
我在做什么错? 感谢您的帮助!
代码:
(该sectionArray和dataArray中都在我的.h文件中的NSMutableArray变量)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
sectionArray = [NSArray arrayWithObjects:@"section1", @"section2", @"section3", nil];
return [sectionArray count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection: (NSInteger)section
{
NSString *sectionHeader = nil;
if(section == 0)
{
sectionHeader = @"אתרים חשובים";
}
if(section == 1)
{
sectionHeader = @"מתעניינים";
}
if(section == 2)
{
sectionHeader = @"טלפונים שימושיים";
}
return sectionHeader;
}
// Returns the number of rows in a given section.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(section == 0)
{
dataArray = [[NSMutableArray alloc] initWithObjects:
@"אתר אורנים",
@"כניסה למערכת ניהול שיעורים",
@"אלפון אנשי סגל",
@"אתר אגודת הסטודנטים",
@"מפת אורנים", nil];
}
if(section == 1)
{
dataArray = [[NSMutableArray alloc] initWithObjects:
@"תנאי קבלה",
@"שאלות נפוצות",
@"הרשמה אונליין",
@"יצירת קשר עם יועץ לימודים",
@"תחבורה ציבורית", nil];
}
if(section == 2)
{
dataArray = [[NSMutableArray alloc] initWithObjects:
@"מרכז המידע וההרשמה",
@"שכר לימוד",
@"שכר לימוד (מספר נוסף)",
@"קופת אורנים",
@"מרכז ההשאלה בספריה", nil];
/*
@"תמיכת הספריה",
@"מעונות",
@"מכלול",
@"רכז בטחון",
@"שער",
@"אגודת הסטודנטים",
@"רדיו אורנים",
@"פקולטות:",
@"מנהל תלמידים",
@"מנהל תלמידים (מספר נוסף)", nil];
*/
}
return [dataArray count];
}
// Returns the cell for a given indexPath.
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
// Create the cell.
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [dataArray objectAtIndex:indexPath.row];
cell.textLabel.textAlignment = UITextAlignmentRight;
float Rvalue = (1.0 * 000)/255;
float Gvalue = (1.0 * 139)/255;
float Bvalue = (1.0 * 69)/255;
cell.textLabel.textColor = [UIColor colorWithRed:Rvalue green:Gvalue blue:Bvalue alpha:1.0f];
UIImage *cellImage = [UIImage imageNamed:@"oranimCellIco.png"];
cell.imageView.image = cellImage;
return cell;
}
正在加载中,请稍候...正在加载... לגביהקוד,סידרתיאותובדיוקכמושרשמתועםאותםשמותמשתניםאבלזהנותןלישתישגיאותבמקומותהבאים: - (NSInteger的)的tableView:(UITableView的*)的tableView numberOfRowsInSection:(NSInteger的)部分{ 的NSArray * dataArray中= [self.data objectAtIndex:indexPath.section]; return [dataArray count]; 使用说明: 使用未声明的标识符'indexpath' –
已有保密声明使用条款隐私声明 המוןהמוןתולהעלהעזרה! –
关于你的问题,这是我的错误...该代码是由我在浏览器中写道和XCode中没有被检查。 应该有: - (NSInteger的)的tableView:(UITableView的*)的tableView numberOfRowsInSection:(NSInteger的)部分{ 的NSArray * dataArray中= [self.data objectAtIndex:节]。 返回[dataArray中计数]; } – Ariel