Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone UITableView创建分区_Iphone_Objective C_Xcode_Uitableview - Fatal编程技术网

iPhone UITableView创建分区

iPhone UITableView创建分区,iphone,objective-c,xcode,uitableview,Iphone,Objective C,Xcode,Uitableview,我试图在UITableView中创建更多的部分,但我似乎无法理解。我希望将“查看完整网站”和“视频”链接移动到自己的部分,并将这些单元格的高度更改为75。我可以创建一个新单元,但我不知道如何正确定位它 typedef enum { SectionHeader, SectionDetail } Sections; typedef enum { SectionHeaderTitle, SectionHeaderDate, SectionHeaderURL, Se

我试图在UITableView中创建更多的部分,但我似乎无法理解。我希望将“查看完整网站”和“视频”链接移动到自己的部分,并将这些单元格的高度更改为75。我可以创建一个新单元,但我不知道如何正确定位它

    typedef enum { SectionHeader, SectionDetail } Sections;
    typedef enum { SectionHeaderTitle, SectionHeaderDate, SectionHeaderURL,            SectionHeaderEnclosure } HeaderRows;
    typedef enum { SectionDetailSummary } DetailRows;

    @implementation MediaDetailTableViewController

    @synthesize item, dateString, summaryString, teachings;

    #pragma mark -
    #pragma mark Initialization

    - (id)initWithStyle:(UITableViewStyle)style {
    if ((self = [super initWithStyle:style])) {

    }
    return self;
    }

    #pragma mark -
    #pragma mark View lifecycle

    - (void)viewDidLoad {

    // Super
    [super viewDidLoad];

    // Date
    if (item.date) {
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateStyle:NSDateFormatterMediumStyle];
        [formatter setTimeStyle:NSDateFormatterMediumStyle];
        self.dateString = [formatter stringFromDate:item.date];
        [formatter release];}
    // Summary
    if (item.summary) {
        self.summaryString = [item.summary stringByConvertingHTMLToPlainText];
    } else {
        self.summaryString = @"[No Summary]";
        }
        }

    #pragma mark -
    #pragma mark Table view data source

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 2;
    }


    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    switch (section) {
        case 0: return 4;
        default: return 1;
    }
        }

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

    // Get cell
    static NSString *CellIdentifier = @"CellA";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    // Display
    cell.textLabel.textColor = [UIColor blackColor];
    cell.textLabel.font = [UIFont systemFontOfSize:15];
    if (item) {

        // Item Info
        NSString *itemTitle = item.title ? [item.title stringByConvertingHTMLToPlainText] : @"[No Title]";

        // Display
        switch (indexPath.section) {
            case SectionHeader: {

                // Header
                switch (indexPath.row) {
                    case SectionHeaderTitle:
                        cell.textLabel.font = [UIFont boldSystemFontOfSize:15];
                        cell.textLabel.text = itemTitle;
                        break;
                    case SectionHeaderDate:
                        cell.textLabel.text = dateString ? dateString : @"[No Date]";
                        break;
                    case SectionHeaderURL:
                        cell.textLabel.text = @"View Full Website";
                        cell.textLabel.textColor = [UIColor blackColor];
                        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
                        cell.imageView.image = [UIImage imageNamed:@"Safari.png"];
                        break;
                    case SectionHeaderEnclosure:
                        cell.textLabel.text = @"Video";
                        cell.textLabel.textColor = [UIColor blackColor];
                        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
                        cell.imageView.image = [UIImage imageNamed:@"Video.png"];
                        break;
                }
                break;

            }
            case SectionDetail: {

                // Summary
                cell.textLabel.text = summaryString;
                cell.textLabel.numberOfLines = 0; // Multiline
                break;

            }
        }
    }

    return cell;

}

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == SectionHeader) {

        // Regular
        return 34;

    } else {

        // Get height of summary
        NSString *summary = @"[No Summary]";
        if (summaryString) summary = summaryString;
        CGSize s = [summary sizeWithFont:[UIFont systemFontOfSize:15] 
                       constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, MAXFLOAT)  // - 40 For cell padding
                           lineBreakMode:UILineBreakModeWordWrap];
        return s.height + 16; // Add padding

    }
    }

    #pragma mark -
    #pragma mark Table view delegate

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    // Open URL
    if (indexPath.section == SectionHeader && indexPath.row == SectionHeaderURL) {
        if (item.link) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:item.link]];
        }
    }

    if (indexPath.section == SectionHeader && indexPath.row == SectionHeaderEnclosure) {  
        if (item.enclosures) {  
            for (NSDictionary *dict in item.enclosures){ 

                NSString *baseUrl = @"http://www.calvaryccm.com";
                NSString *url = [dict objectForKey:@"url"];
                NSString *finalURL;
                finalURL = [baseUrl stringByAppendingFormat:url];
                NSLog(@" finalUrl is : %@",finalURL);
                NSLog(@" Url is : %@",url);

                MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:finalURL]];


                // Register to receive a notification when the movie has finished playing.  
                //[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];  

                if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {  
                    // Use the 3.2 style API  
                    moviePlayer.controlStyle = MPMovieControlStyleDefault;  
                    moviePlayer.shouldAutoplay = YES;  
                    [self.view addSubview:moviePlayer.view];  
                    [moviePlayer setFullscreen:YES animated:YES];  
                } else {  
                    // Use the 2.0 style API  
                    moviePlayer.movieControlMode = MPMovieControlModeHidden;  
                    [moviePlayer play];  
                }           
            }  
        }  
    } 

    // Deselect
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];

    }

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
    // Return YES for supported orientations
    return YES;
    }


    #pragma mark -
    #pragma mark Memory management

    - (void)dealloc {
    [dateString release];
    [summaryString release];
    [item release];
    [teachings release];
    [super dealloc];
    }


    @end
以下是一张供参考的图片:


谢谢你的帮助

您应该从更改
UITableView
的数据源中的适当方法开始

从代码中,您需要将其更改为以下内容:

typedef enum { SectionHeader, SectionMiddle, SectionDetail } Sections;

#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 3;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section    {
    // Return the number of rows in the section.
    switch (section) {
        case 0: return 2;
        case 1: return 2;
        default: return 1;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    // snip
    switch (indexPath.section) {
        case SectionHeader:
           // snip
           break;
        case SectionMiddle:
           // snip
           break;
        case SectionDetail:
           // snip
           break;
    }
}
使用

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 3;
}