2011-12-27 7 views
0

我有8個陣列索引的tableview像指數的tableview

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { 
    NSMutableArray *tempArray = [[NSMutableArray alloc] init]; 
    [tempArray addObject:@"GEN"]; 
    [tempArray addObject:@"1SA"]; 
    [tempArray addObject:@"EST"]; 
    [tempArray addObject:@"EZE"]; 
    [tempArray addObject:@"NAH"]; 
    [tempArray addObject:@"JOH"]; 
    [tempArray addObject:@"COL"]; 
    [tempArray addObject:@"REV"];  
    return tempArray; 
} 

和我得到的一切權利,我的問題是,當我點擊它重定向到另一個頁面,只有第一個數組值的細胞,其是[tempArray addObject:@"GEN"];裏面的價值,我挖掘[tempArray addObject:@"1SA"];等等等等的價值觀,我得到的值客棧[tempArray addObject:@"GEN"];。我didSelectRowAtIndexPath方法是這樣的

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
ChapterSelectionView *detailViewController = [[ChapterSelectionView alloc] initWithNibName:@"ChapterSelectionView" bundle:nil]; 

    //detailViewController.firstString = firstString; 
    // ... 
    // Pass the selected object to the new view controller. 
    detailViewController.selectedIndex=indexPath.row; 
    detailViewController.selectedCountry = selectedCountry; 
    appDelegate.selectedBookIndex=indexPath.row; 


    self.hidesBottomBarWhenPushed=YES; 
    [self.navigationController pushViewController:detailViewController animated:YES]; 

    [detailViewController release]; 
} 

這是我的完整實現代碼如下代碼

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { 

    return index % 8; 
} 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return [books count]; 
} 

我viewDidLoad中這個樣子的

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    l 
    appDelegate=(Malayalam_BibleAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    s"; 



    books = [[NSMutableArray alloc] init]; 

    NSArray *biblearray1 = [NSArray arrayWithObjects:@"Genesis", 
             @"Exodus", 
             @"Leviticus", 
             @"Numbers", 
             @"Deuteronomy", 
             @"Joshua", 
             @"Judges", 
             @"Ruth", nil]; 
    NSDictionary *bibledic1 = [NSDictionary dictionaryWithObject:biblearray1 forKey:@"Countries"]; 

    NSArray *biblearray2 = [NSArray arrayWithObjects:@"1Samuel", 
          @"2Samuel", 
          @"1King", 
          @"2King", 
          @"1Chronicles", 
          @"2Chronicles", 
          @"Ezra", 
          @"Nehemiah", nil]; 
    ......etc etc 


    [books addObject:bibledic1]; 
    [books addObject:bibledic2]; 
     .....etc etc 
} 

// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    NSDictionary *dictionary = [books objectAtIndex:section]; 
    NSArray *array = [dictionary objectForKey:@"Countries"]; 
    return [array count]; 
} 


// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

    } 
    UIView *myBackView = [[UIView alloc] initWithFrame:cell.frame]; 
    myBackView.backgroundColor = [UIColor brownColor]; 
    // [myBackView setBackgroundColor:[UIColor colorWithRed:1 green:1 blue:0.75 alpha:1]]; 
    cell.selectedBackgroundView = myBackView; 
    [myBackView release]; 
    // Configure the cell. 
    // cell.textLabel.tag =row*1+col; 

    //First get the dictionary object 
    NSDictionary *dictionary = [books objectAtIndex:indexPath.section]; 
    NSArray *array = [dictionary objectForKey:@"Countries"]; 
    //NSString *cellValue = [array objectAtIndex:indexPath.row]; 
    cell.textLabel.text =[array objectAtIndex:indexPath.row]; 
    cell.textLabel.highlightedTextColor = [UIColor darkGrayColor]; 
    //cell.textLabel.text = [books objectAtIndex:indexPath.row]; 
    cell.textLabel.font = [UIFont fontWithName:@"Georgia" size:18.0]; 
    cell.textLabel.textColor = [UIColor darkGrayColor]; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;; 

    return cell; 
} 

如何從tableview中的細胞正確的價值觀。 在此先感謝。 編輯

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [[self navigationController] setNavigationBarHidden:YES animated:NO]; 
    scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,49,320,480)]; 
    appDelegate = (Malayalam_BibleAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    //self.navigationItem.title=[appDelegate.books objectAtIndex:selectedIndex]; 
    chapterlabel.text = [appDelegate.books objectAtIndex:selectedIndex]; 
    buttonArray =[[NSMutableArray alloc]initWithCapacity:0]; 
    //self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg10"]]; 

     [self.view addSubview:scrollView]; 


} 
-(void)viewWillAppear:(BOOL)animated{ 
    [super viewWillAppear:YES]; 
    [[self navigationController] setNavigationBarHidden:YES animated:NO]; 

    n=[DbHandler mNumberOfChaptersInBook:[appDelegate.books objectAtIndex:selectedIndex]]; 
    int scrollViewHieght=n/6; 
    scrollView.contentSize = CGSizeMake(320,10+34*scrollViewHieght); 

    i=1; 

    int rowCount=n/6; 
    for(int row=0;row<=rowCount;row++){ 
     for (int col = 0; col < 6; col++) { 
      if(i<=n){ 
       UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
       button.titleLabel.textColor=[UIColor blueColor]; 
       button.titleLabel.font = [UIFont fontWithName:@"Georgia" size:15.0]; 
       [button setBackgroundImage:[UIImage imageNamed:@"tabs"] forState:UIControlStateNormal]; 
       [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
       //button.frame=CGRectMake(col*52+5,row*34+50,50,32); 
       button.frame=CGRectMake(col*52+5,row*34+0,50,32); 
       [button addTarget:self action:@selector(ButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; 
       [button setTitle:[NSString stringWithFormat:@"%d",i++] forState:UIControlStateNormal]; 
       //button.titleLabel.font=[UIFont boldSystemFontOfSize:15]; 
       button.titleLabel.textColor=[UIColor blackColor]; 
       button.tag =row*6+col; 
       [buttonArray addObject:button]; 
       [scrollView addSubview:[buttonArray objectAtIndex:row*6+col]]; 
       //[self.view addSubview:button]; 
       [button release]; 
      } 
     } 
    } 



} 

回答

0

還需要發送部分號碼給detailViewController。根據不同部分,您必須選擇所需的陣列。

+0

但如何?任何ideaaaa? – stackiphone 2011-12-29 04:05:09

+0

詳細VC爲selectedSection添加一個變量,從didSelect方法中,您可以從indexPath.section中獲取節。將此值傳遞給detailVC,然後您可以使用節值。 – vishy 2011-12-29 09:23:31

+0

你可以提供一些代碼嗎?Thnks。 – stackiphone 2011-12-30 05:47:21