Ios 是否可在滚动视图或表格视图标题中使用?

Ios 是否可在滚动视图或表格视图标题中使用?,ios,objective-c,uitableview,uiimage,Ios,Objective C,Uitableview,Uiimage,我目前正在构建一个应用程序,将一些数据解析到UITableView。我正在使用自定义的UITableViewCell类 我想在UITableView之前和顶部添加一个UIImage,就像下面的UIImage一样。我的问题是我是否应该去一个head并创建一个包含UIImage的自定义UITableView标题视图?或者我是否应该将UITableView和UIImageView放在UIScrollView中 我该怎么做 当我在UITableView中滚动时,我希望顶部的UIImage消失,就像它是表

我目前正在构建一个应用程序,将一些数据解析到
UITableView
。我正在使用自定义的
UITableViewCell

我想在
UITableView
之前和顶部添加一个
UIImage
,就像下面的
UIImage
一样。我的问题是我是否应该去一个head并创建一个包含
UIImage
的自定义
UITableView
标题视图?或者我是否应该将
UITableView
UIImageView
放在
UIScrollView

我该怎么做

当我在
UITableView
中滚动时,我希望顶部的
UIImage
消失,就像它是表视图中的一行一样

图片(John Mayer在Tour应用程序上:

我真的很感激一些解决方案

谢谢

编辑:

以下是完整的.m代码:

#import "DEMOSecondViewController.h"
#import "DEMONavigationController.h"
#import "PostsObject.h"
#import "RNBlurModalView.h"
#import "AFNetworking.h"
#import "PostsNextView.h"

#import "KIImagePager.h"
#import "TableHeaderView.h"

#import "DEMOMenuViewController.h"
#import "UIViewController+REFrostedViewController.h"

@interface DEMOSecondViewController ()  <KIImagePagerDelegate, KIImagePagerDataSource>
{
    IBOutlet KIImagePager *_imagePager;
}

@end

@implementation DEMOSecondViewController
@synthesize tableView = _tableView, activityIndicatorView = _activityIndicatorView;
@synthesize fontForCellText;
@synthesize btnFaceBook, btnTwitter, btnTwitter2;
@synthesize strURLToLoad;
@synthesize movies;

- (IBAction)showButtonMenu {
    [self.frostedViewController presentMenuViewController];
}

- (void)refresh:(UIRefreshControl *)refreshControl {
    [refreshControl endRefreshing];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
    [refreshControl setTintColor:[UIColor greenColor]];
    [refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
    [self.tableView addSubview:refreshControl];
    
    strURLToLoad = [[NSMutableString alloc] init];
    
    [btnFaceBook setTitle:@"link-1" forState:UIControlStateDisabled];
    [btnTwitter setTitle:@"link-2" forState:UIControlStateDisabled];
    [btnTwitter2 setTitle:@"link-3" forState:UIControlStateDisabled];
    
    [btnFaceBook setBackgroundImage:[UIImage imageNamed:@"tab_selected.png"] forState:UIControlStateNormal];
    [btnFaceBook setBackgroundImage:[UIImage imageNamed:@"tab_unselected.png"] forState:UIControlStateSelected];
    
    [btnTwitter setBackgroundImage:[UIImage imageNamed:@"tab_selected.png"] forState:UIControlStateNormal];
    [btnTwitter setBackgroundImage:[UIImage imageNamed:@"tab_unselected.png"] forState:UIControlStateSelected];
    
    [btnTwitter2 setBackgroundImage:[UIImage imageNamed:@"tab_selected.png"] forState:UIControlStateNormal];
    [btnTwitter2 setBackgroundImage:[UIImage imageNamed:@"tab_unselected.png"] forState:UIControlStateSelected];
    
    
    
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"PostsObject" owner:self options:nil];
    PostsObject *cell = [nib objectAtIndex:0];
    fontForCellText = cell.title.font;
    cellTextWidth = cell.title.frame.size.width;
    cellHeightExceptText = cell.frame.size.height - cell.title.frame.size.height;
    
    [self.navigationController setNavigationBarHidden:YES];
    
    self.tableView.separatorColor = [UIColor clearColor];
    
    // Setting Up Activity Indicator View
    self.activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    
    self.activityIndicatorView.color = [UIColor greenColor];
    
    
    self.activityIndicatorView.hidesWhenStopped = YES;
    self.activityIndicatorView.center = self.view.center;
    [self.view addSubview:self.activityIndicatorView];
    [self.activityIndicatorView startAnimating];
    self.tableView.separatorColor = [UIColor clearColor];
    
    // Initializing Data Source
    movies = [[NSMutableArray alloc] init];
    
    [self btnFromTabBarClicked:btnFaceBook];
}

-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

- (void)loadJSONFromCurrentURL
{
    [self.activityIndicatorView startAnimating];
    
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:strURLToLoad]];
    
    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
        [movies setArray:JSON];
        [self.activityIndicatorView stopAnimating];
        [self.tableView reloadData];
        
    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
        NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo);
    }];
    
    [operation start];
}

- (IBAction)btnFromTabBarClicked:(UIButton *)sender
{
    //Unselect all 3 buttons
    btnFaceBook.selected = btnTwitter.selected = btnTwitter2.selected = NO;
    
    //Select the button that was clicked
    sender.selected = YES;
    
    //Set the string of an NSMutableString property called strURLToLoad with the URL
    //The URL is pre stored in the text of the UIButton in the Disabled text.
    [strURLToLoad setString:[sender titleForState:UIControlStateDisabled]];
    
    //Load the URL
    [self loadJSONFromCurrentURL];
}

// How can I set an if-statement here? If the section is 0, return only 1 row, otherwise, the if (movies) function...

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (movies && movies.count) {
        return movies.count;
    } else {
        return 0;
    }
}

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        static NSString *Identifier1 = @"TableHeaderView";
        // cell type 1
        TableHeaderView *cell = [tableView dequeueReusableCellWithIdentifier:Identifier1];
        if (cell == nil) {
            NSArray *nib= [[NSBundle mainBundle] loadNibNamed:@"TableHeaderView" owner:self options:nil];
            cell = (TableHeaderView *)[nib objectAtIndex:0];
        }
        
        //set the image on the cell
        
        return cell;
    } else {
        
        static NSString *Identifier2 = @"PostsObject";
        // cell type 2
        PostsObject *cell = [tableView dequeueReusableCellWithIdentifier:Identifier2];
        if (cell == nil) {
            NSArray *nib= [[NSBundle mainBundle] loadNibNamed:@"PostsObject" owner:self options:nil];
            cell = (PostsObject *)[nib objectAtIndex:0];
        }
        
        NSDictionary *movie = [self.movies objectAtIndex:indexPath.row];
        NSString *strText = [movie objectForKey:[self getTextKey]];
        
        CGRect rect = cell.title.frame;
        rect.size.height = [self getHeightForText:strText];
        cell.title.frame = rect;
        cell.title.text = strText;
        cell.arrow.center = CGPointMake(cell.arrow.frame.origin.x, rect.origin.y + rect.size.height/2);
        cell.published.text = [movie objectForKey:[self getPostedTime]];
        cell.twitterName.text = [movie objectForKey:[self getTwitterName]];
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSDictionary *selectedMovie = self.movies[indexPath.row];
    
    PostsNextView *nextVC = [[PostsNextView alloc] initWithDictionary:movies];
    
    [self.navigationController pushViewController:nextVC animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *movie = [self.movies objectAtIndex:indexPath.row];
    NSString *strText = [movie objectForKey:[self getTextKey]];
    
    CGFloat cellHeight = cellHeightExceptText + [self getHeightForText:strText];
    
    return cellHeight;
}

- (NSString *)getTextKey
{
    return btnTwitter.selected?@"tweet":@"message";
}

- (NSString *)getPostedTime
{
    return btnTwitter.selected?@"posted":@"published";
}

- (NSString *)getTwitterName
{
    return btnTwitter2.selected?@"user":@"celebname";
}

- (CGFloat)getHeightForText:(NSString *)strText
{
    CGSize constraintSize = CGSizeMake(cellTextWidth, MAXFLOAT);
    CGSize labelSize = [strText sizeWithFont:fontForCellText constrainedToSize:constraintSize lineBreakMode:NSLineBreakByWordWrapping];
    NSLog(@"labelSize.height = %f",labelSize.height);
    return labelSize.height;
}


@end
#导入“DEMOSecondViewController.h”
#导入“DEMONavigationController.h”
#导入“PostsObject.h”
#导入“RNBlurModalView.h”
#导入“AFNetworking.h”
#导入“PostsNextView.h”
#导入“KIImagePager.h”
#导入“TableHeaderView.h”
#导入“DEMOMenuViewController.h”
#导入“UIViewController+REFrostedViewController.h”
@接口DEMOSecondViewController()
{
IBU图像寻呼机*\U图像寻呼机;
}
@结束
@SecondViewController的实现
@综合表视图=_表视图,活动指示器视图=_活动指示器视图;
@综合文本;
@合成btnFaceBook,btnTwitter,btnTwitter2;
@综合结构荷载;
@综合电影;
-(iAction)显示按钮菜单{
[self.frostedViewController presentMenuViewController];
}
-(无效)刷新:(UIRefreshControl*)刷新控件{
[刷新控制结束刷新];
}
-(无效)viewDidLoad
{
[超级视图下载];
//加载视图后,通常从nib执行任何其他设置。
UIRefreshControl*refreshControl=[[UIRefreshControl alloc]init];
[refreshControl setTintColor:[UIColor greenColor]];
[refreshControl添加目标:自我操作:@selector(refresh:)forControlEvents:UIControlEventValueChanged];
[self.tableView addSubview:refreshControl];
strurltoad=[[NSMutableString alloc]init];
[btnFaceBook集合标题:@“链接-1”用于状态:UIControlStateDisabled];
[btnTwitter设置标题:@“链接-2”用于状态:uicontrol状态禁用];
[btnTwitter2设置标题:@“链接-3”用于状态:UIControlStateDisabled];
[btnFaceBook setBackgroundImage:[UIImage ImageName:@“tab_selected.png”]用于状态:UIControlStateNormal];
[btnFaceBook setBackgroundImage:[UIImage ImageName:@“tab_unselected.png”]用于状态:UIControlStateSelected];
[btnTwitter setBackgroundImage:[UIImage ImageName:@“tab_selected.png”]用于状态:UIControlStateNormal];
[btnTwitter setBackgroundImage:[UIImage ImageName:@“tab_unselected.png”]用于状态:UIControlStateSelected];
[btnTwitter2 setBackgroundImage:[UIImage ImageName:@“tab_selected.png”]用于状态:UIControlStateNormal];
[btnTwitter2 setBackgroundImage:[UIImage ImageName:@“tab_unselected.png”]用于状态:UIControlStateSelected];
NSArray*nib=[[NSBundle mainBundle]loadNibNamed:@“PostsObject”所有者:自选项:nil];
PostsObject*单元格=[nib objectAtIndex:0];
fontForCellText=cell.title.font;
cellTextWidth=cell.title.frame.size.width;
cellHeightExceptText=cell.frame.size.height-cell.title.frame.size.height;
[self.navigationController设置NavigationBarHidden:是];
self.tableView.separatorColor=[UIColor clearColor];
//设置活动指示器视图
self.activityIndicatorView=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
self.activityIndicatorView.color=[UIColor greenColor];
self.activityIndicatorView.hidesWhenStopped=是;
self.activityIndicatorView.center=self.view.center;
[self.view addSubview:self.activityIndicatorView];
[self.activityIndicatorView startAnimating];
self.tableView.separatorColor=[UIColor clearColor];
//初始化数据源
movies=[[NSMutableArray alloc]init];
[自btnfromtabbar点击:btnFaceBook];
}
-(UIStatusBarStyle)首选状态BarStyle{
返回UIStatusBarStyleLightContent;
}
-(void)loadJSONFromCurrentURL
{
[self.activityIndicatorView startAnimating];
NSURLRequest*request=[[NSURLRequest alloc]initWithURL:[NSURL URLWithString:strURLToLoad]];
AFJSONRequestOperation*操作=[AFJSONRequestOperation JSONRequestOperationWithRequest:请求成功:^(NSURLRequest*请求,NSHTTPURLRResponse*响应,id JSON){
[电影集数组:JSON];
[self.activityIndicatorView停止设置动画];
[self.tableView重载数据];
}失败:^(NSURLRequest*请求,NSHTTPURLResponse*响应,NSError*错误,id JSON){
NSLog(@“请求失败,错误为:%@,%@”,错误为,错误为.userInfo);
}];
[操作启动];
}
-(iAction)BtnFromTabbar单击:(UIButton*)发件人
{
//取消选择所有3个按钮
btnFaceBook.selected=btnTwitter.selected=btnTwitter2.selected=NO;
//选择单击的按钮
sender.selected=是;
//使用URL设置名为strURLToLoad的NSMutableString属性的字符串
//URL预先存储在禁用文本中UIButton的文本中。
[strURLToLoad设置字符串:[发送方标题ForState:UIControlStateDisabled];
//加载URL
[self-loadJSONFromCurrentURL];
}
//如何在此处设置if语句?如果节为0,则仅返回1行,否则,if(movies)函数。。。
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节{
if(movies&&movies.count){
返回电影。计数;
}否则{
返回0;
}
}
-(NSInteger)表格视图中的节数:(UITableView*)表格视图{
返回2;
}
-(U)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        static NSString *Identifier1 = @"CellType1";
        // cell type 1
        CellType1 *cell = [tableView dequeueReusableCellWithIdentifier:Identifier1];
        if (cell == nil) {
            NSArray *nib= [[NSBundle mainBundle] loadNibNamed:@"CellType1" owner:self options:nil];
            cell = (CellType1 *)[nib objectAtIndex:0];    
        }

        //set the image on the cell

        return cell;
    } else {
        static NSString *Identifier1 = @"CellType2";
        // cell type 2
        CellType2 *cell = [tableView dequeueReusableCellWithIdentifier:Identifier2];
        if (cell == nil) {
            NSArray *nib= [[NSBundle mainBundle] loadNibNamed:@"CellType2" owner:self options:nil];
            cell = (CellType2 *)[nib objectAtIndex:0];     
        }

        // set cell with breaking news stuff

        return cell;
    }
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section==0) {
        return 1;
    } else {
        return BREAKING_NEWS_COUNT;
    }
}