UITabelView GroupStyle 不同Section中自定义Cell For Row(xib模式)

来源:互联网 发布:淘宝店企业转个人 编辑:程序博客网 时间:2024/05/16 08:53

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return 3;

}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    if (section == 0) {

        return 1;

    }else if (section == 1){

        return 4;

    }else if (section == 2){

        return 1;

    }

    return 1;

}


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

{

    UITableViewCell *cell = nil;

    if (indexPath.section == 0) {

        cell = [self createSection1:indexPath];

    }else if (indexPath.section == 1){

        cell = [self createSection2:indexPath];

    }else if (indexPath.section == 2){

        cell = [self createSection3:indexPath];

    }

    return cell;

}


- (UITableViewCell*)createSection1:(NSIndexPath *)indexPath

{

   static NSString *cellIdentifier = @"ImageCell";

    UITableViewCell *cell = (ImageCell *)[ContentTableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (indexPath.row == 0) {

        if (cell == nil) {

            NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"ImageCell" owner:self options:nil];

            for (id obj in nib) {

                if ([obj isKindOfClass:[ImageCell class]]) {

                    cell = (ImageCell *)obj;

                }

            }

        }

        if (self.index == 1) {

            [((ImageCell *)cell).TopImageView setImageWithURL:(NSURL *)touristImage];

        }

    }

    return cell;

}


- (UITableViewCell*)createSection2:(NSIndexPath *)indexPath

{

    UITableViewCell *cell = nil;

    static NSString *cellIdentifier = @"Cell";

    if (indexPath.row == 0) {

        cell = (FactsCell *)[ContentTableView dequeueReusableCellWithIdentifier:cellIdentifier];

        if (cell == nil) {

            NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"FactsCell" owner:self options:nil];

            for (id obj in nib) {

                if ([obj isKindOfClass:[FactsCell class]]) {

                    cell = (FactsCell *)obj;

                }

            }


    }

        }else if (indexPath.row == 1){

        cell = (MutiDetailCell *)[ContentTableView dequeueReusableCellWithIdentifier:cellIdentifier];

        if (cell == nil) {

            NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"MutiDetailCell" owner:self options:nil];

            for (id obj in nib) {

                if ([obj isKindOfClass:[MutiDetailCell class]]) {

                    cell = (MutiDetailCell *)obj;

                }

            }

        }

        

        }else {

            cell = (PlusCell *)[ContentTableView dequeueReusableCellWithIdentifier:cellIdentifier];

            if (cell == nil) {

                NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"PlusCell" owner:self options:nil];

                for (id obj in nib) {

                    if ([obj isKindOfClass:[PlusCell class]]) {

                        cell = (PlusCell *)obj;

                    }

                }

            }


        }

    if (indexPath.row == 0) {

        ((FactsCell *)cell).playLabel.text = @"2小时";

        ((FactsCell *)cell).opentimeLabel.text = @"上午 9:00 -下午 5:00";

    }

    else if (indexPath.row == 1) {

        ((MutiDetailCell *)cell).thumbView.image = IMAGE_WITH_NAME2(@"Tickets");

        ((MutiDetailCell *)cell).priceLabel.text = @"50";

    }

    else if (indexPath.row == 2) {

        ((PlusCell *)cell).thumbView.image = IMAGE_WITH_NAME2(@"LandMarks");

        ((PlusCell *)cell).textLabel.text = @"达州市通川区上华路92";

    }

    else if (indexPath.row == 3) {

        ((PlusCell *)cell).thumbView.image = IMAGE_WITH_NAME2(@"PhoneBig");

        ((PlusCell *)cell).textLabel.text = @"028-88888888";

        

    }

    

    return cell;

}


- (UITableViewCell*)createSection3:(NSIndexPath *)indexPath

{

    UITableViewCell *cell = nil;

    static NSString *cellIdentifier = @"SingelCell";

    cell = (SingelCell *)[ContentTableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell == nil) {

        NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"SingelCell" owner:self options:nil];

        for (id obj in nib) {

            if ([obj isKindOfClass:[SingelCell class]]) {

                cell = (SingelCell *)obj;

            }

        }

    }

    return cell;

}



-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    

    if (indexPath.section == 0) {

        return 160;

    }else if(indexPath.section == 1 && indexPath.row == 0){

    return 87;

        

    }else if(indexPath.section == 1 && indexPath.row == 1){

        return 44;

    }

      else if (indexPath.section == 2){

        return 100;

    }


    return 44;

    

}


-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

    return 1;

}



因为是label中的text需要通过网络解析,实在不想去弄了,多建了一个xib.
0 0
原创粉丝点击