I have an issue that my arrays are not set to the sections i want. In the code under:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
Only the second array is set into the section but it repeats its self on the other 2 sections and not set the other sections with the rest of the arrays.
anoter thing i have - if i put in one of the array (let's say the third one) more then 5 rows like the first and the second array, it give me error: Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayM objectAtIndex:]: index 5 beyond bounds [0 .. 4]'
What i'm doing wrong?? Thanks for the help!
The code:
(The sectionArray and dataArray are NSMutableArray variables in my .h file)
- (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;
}