2012-12-19 8 views
7

मैं अपने टेबलव्यू में वेब से अलग डेटा दिखाना चाहता हूं लेकिन मुझे तालिका के एक सेक्शन में अलग-अलग कक्षों में उन्हें दिखाने का तरीका नहीं मिल रहा है, कोई भी मुझे दिखाने में मदद कर सकता है एक कक्षतालिका में 5 अलग-अलग कस्टम कोशिकाओं को जोड़ने के लिए कैसे देखें

cell.textLabel.text=app.i_name; 

दूसरे सेल

cell.textLabel.text=app.i_phone; 

में तीसरे कक्ष में

cell.textLabel.text=app.i_hours; 

आगे सेल

cell.textLabel.text=app.i_address; 

पांचवें सेल में में

cell.textLabel.text=app.i_email; 

सूचकांक में पंक्ति के लिए मेरे सेल

रूप
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *CellIdentifier = @"Single Cell"; 
    SingleCell *cell =(SingleCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 


    if (cell == nil) { 
     UIViewController *c = [[UIViewController alloc] initWithNibName:@"SingleCell" bundle:nil]; 
     cell = (SingleCell *) c.view; 
     //[c release]; 

    } 
appDC * application = [dataArray objectAtIndex:[indexPath row]]; 

     //cell.namelbl.text=application.application_name; 


return cell; 
} 
+0

के लिए इस कोड को किसी भी एक का उपयोग कर सकते के लिए इस कोड को धन्यवाद करके इस सवाल का हल? – NullData

+2

IMHO यदि आप कुछ और उत्तरों स्वीकार करते हैं तो आपको बहुत अधिक सहायता मिल जाएगी। यह सिर्फ एसओ पर मेरा अनुभव रहा है। –

+1

इसके अलावा, क्या आप 5 अलग-अलग कस्टम सेल बनाने या "स्टॉक आईओएस" UITableViewCells के साथ डेटा को बदलने के तरीके के बारे में पूछ रहे हैं? –

उत्तर

5

इस कोड का प्रयास करें है:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *CellIdentifier = @"Single Cell"; 
    SingleCell *cell =(SingleCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 


    if (cell == nil) { 
     UIViewController *c = [[UIViewController alloc] initWithNibName:@"SingleCell" bundle:nil]; 
     cell = (SingleCell *) c.view; 
     //[c release]; 

    } 
    appDC * application = [dataArray objectAtIndex:[indexPath row]]; 

    //cell.namelbl.text=application.application_name; 
    if (indexPath.row == 0) 
    { 
     cell.textLabel.text=application.i_name; 
    } 
    else if (indexPath.row == 1) 
    { 
     cell.textLabel.text = application.i_iphone; 
    } 
    else if (indexPath.row == 2) 
    { 
     cell.textLabel.text = application.i_hours; 
    } 
    else if (indexPath.row == 3) 
    { 
     cell.textLabel.text = application.i_address; 
    } 
    else 
    { 
     cell.textLabel.text = application.i_email; 
    } 



    return cell; 
} 

आशा इस जवाब मदद करेगा। चीयर्स

+0

मैंने पहले ही यह कोशिश की है कि यह मुझे पहले सेल दे :( – NullData

+0

क्या आप फिर कोशिश कर सकते हैं? मुझे टेक्स्ट ऑब्जेक्ट को मूल्य पास करने के लिए एक ही ऑब्जेक्ट का उपयोग नहीं किया गया है तो, क्या आप सुनिश्चित हैं कि आपकी ऑब्जेक्ट प्रॉपर्टी एनएसएसटींग का प्रकार है? – IKQ

+3

मेरा मानना ​​है कि पूछताछकर्ता एक तत्व में सरणी में प्रत्येक तत्व से सभी डेटा प्राप्त करने का प्रयास कर रहा है ... मुझे लगता है कि यह केवल उसे पहला सेल देता है क्योंकि उसकी सरणी में केवल एक तत्व होता है और जब ऐप तालिका को पॉप्युलेट करने का प्रयास करता है तो यह केवल उसे पहला सेल देता है। एक कस्टम सेल को निश्चित रूप से "एप्लिकेशन" ऑब्जेक्ट में निकाले जाने वाले सभी डेटा को समायोजित करने के लिए बनाया जाना चाहिए सरणी "डेटाअरे" इस लिंक को http: // stackoverflow देखें।com/प्रश्न/4917027/ios-steps-to-create-custom-uitableviewcell-with-xib-file –

1

आईकेक्यू के कोड उदाहरण को काम करना चाहिए। लेकिन मैं अपने TableKit लाइब्रेरी को आजमाने का सुझाव देता हूं। इस तरह से कोड और अधिक स्पष्ट और सुरुचिपूर्ण होगा:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    TKStaticCell* nameCell = [TKStaticCell cellWithStyle:UITableViewCellStyleValue1 text:@"Name" detailText:app.i_name]; 
    TKStaticCell* phoneCell = [TKStaticCell cellWithStyle:UITableViewCellStyleValue1 text:@"Phone" detailText:app.i_phone]; 
    TKStaticCell* hoursCell = [TKStaticCell cellWithStyle:UITableViewCellStyleValue1 text:@"Hours" detailText:app.i_hours]; 
    TKStaticCell* addressCell = [TKStaticCell cellWithStyle:UITableViewCellStyleValue1 text:@"Address" detailText:app.i_address]; 
    TKStaticCell* emailCell = [TKStaticCell cellWithStyle:UITableViewCellStyleValue1 text:@"email" detailText:app.i_email]; 
    TKSection* section = [TKSection sectionWithCells:nameCell, phoneCell, hoursCell, addressCell, emailCell, nil]; 
    self.sections = [NSArray arrayWithObject:section]; 
} 

इसके अलावा पुस्तकालय TKStaticCell के बजाय कस्टम सेल परिभाषित करने के लिए अनुमति देता है।

2

मैं सब दे रही सुझाव

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *CellIdentifier = @"CellForInfo"; 
    CellForInfo *cell =(CellForInfo *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 


    if (cell == nil) { 
     UIViewController *c = [[UIViewController alloc] initWithNibName:@"CellForInfo" bundle:nil]; 
     cell = (CellForInfo *) c.view; 
     //[c release]; 



    } 

    appDC * application = [dataArray objectAtIndex:0]; 
    if (indexPath.row == 0) 
    { 
     cell.lblinfo.text=application.i_name; 
    } 
    if (indexPath.row == 1) 
    { 
     cell.lblinfo.text = application.i_phone; 
    } 
    if (indexPath.row == 2) 
    { 
     cell.lblinfo.text = application.i_hours; 
    } 
    if (indexPath.row == 3) 
    { 
     cell.lblinfo.text = application.i_address; 
    } 
    if (indexPath.row == 4) 
    { 
     cell.lblinfo.text = application.i_email; 
    } 



    return cell; 
} 
-1
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 

    [self tableInfo]; 
} 


- (void) tableInfo 
{ 

    NSArray *keysArray = @[@"CampaignsName",@"BusinessName",@"BusinessType",@"CampaignsType",@"Distance",@"Daysleft",@"CampaignImage",]; 

    NSArray *valuesArray1 =[NSArray arrayWithObjects:@"5 % OFF ",@"Coffe Shop",@"1",@"1",@"0.10 Miles",@"5 days Left",@"b2.png", nil]; 

    NSArray *valuesArray2 = [NSArray arrayWithObjects:@"win $2 for you & charity ",@"Red Tommato",@"2",@"2",@"20 Miles",@"2 days Left",@"b1.png", nil]; 

    NSArray *valuesArray3 = [NSArray arrayWithObjects:@"Buy dogs food & get a one more",@"Pet Care",@"3",@"3", @"30 Miles",@"10 days Left",@"b2.png", nil]; 

    NSArray *valuesArray4 =[NSArray arrayWithObjects:@"win $2 for you & charity ",@"Red Tommato",@"1",@"1",@"0.10 Miles",@"7 days Left",@"b2.png", nil]; 



    NSDictionary *dict1 = [NSDictionary dictionaryWithObjects:valuesArray1 forKeys:keysArray]; 

    NSDictionary *dict2 = [NSDictionary dictionaryWithObjects:valuesArray2 forKeys:keysArray]; 

    NSDictionary *dict3 = [NSDictionary dictionaryWithObjects:valuesArray3 forKeys:keysArray]; 

    NSDictionary *dict4 = [NSDictionary dictionaryWithObjects:valuesArray4 forKeys:keysArray]; 



    self.tableArray = [[NSArray alloc]initWithObjects:dict1,dict2,dict3,dict4,dict3,dict1,dict4,dict2,nil]; 
    NSLog(@"Array %@",tableArray); 
    [self.tableObj reloadData]; 
} 

#pragma mark table view datasource 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 

} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [self.tableArray count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    UITableViewCell *cell = [self tableCustomView:tableView cellForRowAtIndexPath:indexPath]; 
    return cell; 
} 

- (UITableViewCell *)tableCustomView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *mainCell ; 



    static NSString *CellIdentifier1 = @"CustomCellIdentifier"; 
    static NSString *CellIdentifier2 = @"CustomCellIdentifier2"; 


    if (indexPath.row % 2 != 0) 
    { 
     CustomCell2 *cell2 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2]; 
     if (cell2 == nil) 
     { 

      NSArray *topObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell2" owner:self options:nil]; 
      cell2 = [topObjects objectAtIndex:0]; 
     } 


     id object = [self.tableArray objectAtIndex:indexPath.row]; 


     cell2.CampaignsNameLbl.text = [NSString stringWithFormat:@"%@",[object valueForKey:@"CampaignsName"]]; 
     cell2.BusinessNameLbl.text = [NSString stringWithFormat:@"%@",[object valueForKey:@"BusinessName"]]; 
     cell2.DistanceLbl.text = [NSString stringWithFormat:@"%@",[object valueForKey:@"Distance"]]; 
     cell2.DaysleftLbl.text = [NSString stringWithFormat:@"%@",[object valueForKey:@"Daysleft"]]; 

     cell2.cellBackImg.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",[object valueForKey:@"CampaignImage"]]]; 


     int businessType = [[NSString stringWithFormat:@"%@",[object valueForKey:@"BusinessType"]] integerValue]; 

     NSLog(@": %d",businessType); 

     switch (businessType) 
     { 


      case 1: 

       cell2.cellBusinessTypeImg.image = [UIImage imageNamed:@"RETL[email protected]"]; 

       break; 
      case 2: 

       cell2.cellBusinessTypeImg.image = [UIImage imageNamed:@"BTY.png"]; 

       break; 
      case 3: 

       cell2.cellBusinessTypeImg.image = [UIImage imageNamed:@"t1.png"]; 

       break; 

      default: 
       break; 
     } 


     int CampaignsType = [[NSString stringWithFormat:@"%@",[object valueForKey:@"CampaignsType"]] integerValue]; 

     switch (CampaignsType) 
     { 

      case 1: 

       cell2.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:@"t3.png"]; 

       break; 
      case 2: 

       cell2.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:@"t2.png"]; 

       break; 
      case 3: 

       cell2.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:@"t1.png"]; 

       break; 

      default: 
       break; 
     } 

     mainCell = cell2 ; 


    } 

    else 
    { 
     CustomCell1 *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; 
     if (cell1 == nil) 
     { 

      NSArray *topObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell1" owner:self options:nil]; 
      cell1 = [topObjects objectAtIndex:0]; 
     } 


     id object = [self.tableArray objectAtIndex:indexPath.row]; 


     cell1.CampaignsNameLbl.text = [NSString stringWithFormat:@"%@",[object valueForKey:@"CampaignsName"]]; 
     cell1.BusinessNameLbl.text = [NSString stringWithFormat:@"%@",[object valueForKey:@"BusinessName"]]; 
     cell1.DistanceLbl.text = [NSString stringWithFormat:@"%@",[object valueForKey:@"Distance"]]; 
     cell1.DaysleftLbl.text = [NSString stringWithFormat:@"%@",[object valueForKey:@"Daysleft"]]; 

     cell1.cellBackImg.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",[object valueForKey:@"CampaignImage"]]]; 


     int businessType = [[NSString stringWithFormat:@"%@",[object valueForKey:@"BusinessType"]] integerValue]; 

     NSLog(@": %d",businessType); 

     switch (businessType) 
     { 


      case 1: 

       cell1.cellBusinessTypeImg.image = [UIImage imageNamed:@"[email protected]"]; 

       break; 
      case 2: 

       cell1.cellBusinessTypeImg.image = [UIImage imageNamed:@"BTY.png"]; 

       break; 
      case 3: 

       cell1.cellBusinessTypeImg.image = [UIImage imageNamed:@"t1.png"]; 

       break; 

      default: 
       break; 
     } 


     int CampaignsType = [[NSString stringWithFormat:@"%@",[object valueForKey:@"CampaignsType"]] integerValue]; 

     switch (CampaignsType) 
     { 

      case 1: 

       cell1.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:@"t3.png"]; 

       break; 
      case 2: 

       cell1.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:@"t2.png"]; 

       break; 
      case 3: 

       cell1.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:@"t1.png"]; 

       break; 

      default: 
       break; 
     } 

     mainCell = cell1 ; 
    } 


    return mainCell; 

    NSLog(@"Index Path is :%d %d", indexPath.section,indexPath.row); 
} 
0

आप मेरी मदद कम

  CellForInfo * cellForInfo = (CellForInfo *)[tableView dequeueReusableCellWithIdentifier:nil]; 

      if (cellForInfo ==nil) { 
       NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CellForInfo" owner:self options:nil]; 
       cellForInfo = [nib objectAtIndex:0]; 
      } 
संबंधित मुद्दे