Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.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
如何在ios6&;中显示UIButton和UITableview;ios7适用于4英寸屏幕和3.5英寸屏幕_Ios_Iphone_Objective C_Xcode5 - Fatal编程技术网

如何在ios6&;中显示UIButton和UITableview;ios7适用于4英寸屏幕和3.5英寸屏幕

如何在ios6&;中显示UIButton和UITableview;ios7适用于4英寸屏幕和3.5英寸屏幕,ios,iphone,objective-c,xcode5,Ios,Iphone,Objective C,Xcode5,我正在开发一个应用程序。在应用程序中,我为3.5英寸屏幕编写了代码,为ios7和ios6编写了4英寸屏幕代码。我拿了一个视图控制器;在这个视图控制器中,我想显示两个图像,一个用于顶部,另一个用于底部。同时还显示登录和注销按钮以及登录表视图。在ios7和ios6 3.5英寸屏幕和4英寸屏幕上,显示两个图像(如顶部图像和底部图像)没有问题。这两个图像显示正确。但是按钮和UITableview没有显示。我不明白显示UIButton和UITableview的问题出在哪里。请给我一些想法,任何人。我是编程

我正在开发一个应用程序。在应用程序中,我为3.5英寸屏幕编写了代码,为ios7和ios6编写了4英寸屏幕代码。我拿了一个视图控制器;在这个视图控制器中,我想显示两个图像,一个用于顶部,另一个用于底部。同时还显示登录和注销按钮以及登录表视图。在ios7和ios6 3.5英寸屏幕和4英寸屏幕上,显示两个图像(如顶部图像和底部图像)没有问题。这两个图像显示正确。但是按钮和UITableview没有显示。我不明白显示UIButton和UITableview的问题出在哪里。请给我一些想法,任何人。我是编程新手。提前谢谢

下面是我的代码

Viewcontroller.m(ios7和ios6的3.5英寸和4英寸屏幕)

/************************************************************************************************************/ /ios6和ios7的3.5英寸屏幕/

 else
 {

  if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
   {

    imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 70, 162, 57)];

    imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(0, 345, 320,140 )];

    btnLogin.frame = CGRectMake(20, 200, 127, 32);

    // create Login Tableview

    tableVw=[[UITableView alloc] initWithFrame:CGRectMake(10, 85, 300, 123) style:UITableViewStyleGrouped];

   }

   else
   {

    imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 50, 162, 57)];

    imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(0, 325, 320,140 )];

    btnLogin.frame = CGRectMake(20, 200, 127, 32);

    tableVw=[[UITableView alloc] initWithFrame:CGRectMake(10, 85, 300, 123) style:UITableViewStyleGrouped];

   }

   imgLogo.image=[UIImage imageNamed:@"Logo-01.png"];

   [self.view addSubview:imgLogo];

   imgBuilding.image=[UIImage imageNamed:@"image-02.png"];

   imgBuilding.alpha=0.4;

   [self.view addSubview:imgBuilding];

   // Create Button Properties

   btnLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];

   [btnLogin addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchDown];

   [btnLogin setBackgroundImage:[UIImage imageNamed:@"Sign-in-button.png"] forState:UIControlStateNormal];

   [self.view addSubview:btnLogin];

   // Create Login Tableview properties

   tableVw.dataSource = self;     
   tableVw.delegate = self;

   tableVw.backgroundColor=[UIColor clearColor];

   tableVw.scrollEnabled=NO;

   tableVw.scrollsToTop=NO;

   [self.view addSubview:tableVw];


   }

  }
/************************************************************************************************************/

 else
 {

  if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
   {

    imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 70, 162, 57)];

    imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(0, 345, 320,140 )];

    btnLogin.frame = CGRectMake(20, 200, 127, 32);

    // create Login Tableview

    tableVw=[[UITableView alloc] initWithFrame:CGRectMake(10, 85, 300, 123) style:UITableViewStyleGrouped];

   }

   else
   {

    imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 50, 162, 57)];

    imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(0, 325, 320,140 )];

    btnLogin.frame = CGRectMake(20, 200, 127, 32);

    tableVw=[[UITableView alloc] initWithFrame:CGRectMake(10, 85, 300, 123) style:UITableViewStyleGrouped];

   }

   imgLogo.image=[UIImage imageNamed:@"Logo-01.png"];

   [self.view addSubview:imgLogo];

   imgBuilding.image=[UIImage imageNamed:@"image-02.png"];

   imgBuilding.alpha=0.4;

   [self.view addSubview:imgBuilding];

   // Create Button Properties

   btnLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];

   [btnLogin addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchDown];

   [btnLogin setBackgroundImage:[UIImage imageNamed:@"Sign-in-button.png"] forState:UIControlStateNormal];

   [self.view addSubview:btnLogin];

   // Create Login Tableview properties

   tableVw.dataSource = self;     
   tableVw.delegate = self;

   tableVw.backgroundColor=[UIColor clearColor];

   tableVw.scrollEnabled=NO;

   tableVw.scrollsToTop=NO;

   [self.view addSubview:tableVw];


   }

  }

试试这个代码。我修改了你的代码

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
        self.edgesForExtendedLayout = UIRectEdgeNone;

    UIImageView *imgLogo;
    UIImageView *imgBuilding;
    UIButton *btnLogin = [UIButton buttonWithType:UIButtonTypeCustom];
    UITableView *tableVw;
    if ([[UIScreen mainScreen] bounds].size.height == 568){

        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7){

            imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 65, 162, 57)];
            imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(8, 415, 300, 153 )];

            btnLogin.frame = CGRectMake(20, 230, 127, 32);

            tableVw=[[UITableView alloc] initWithFrame:CGRectMake(0, 123, 320, 100) style:UITableViewStylePlain];
        }else{

            imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 45, 162, 57)];

            imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(8, 395, 300, 153 )];



            btnLogin.frame = CGRectMake(20, 210, 127, 32);

            tableVw=[[UITableView alloc] initWithFrame:CGRectMake(0, 103, 320, 100) style:UITableViewStylePlain];
        }

        imgLogo.image=[UIImage imageNamed:@"icon.png"];
        [self.view addSubview:imgLogo];
        imgBuilding.image=[UIImage imageNamed:@"icon.png"];
        imgBuilding.alpha=0.4;
        [self.view addSubview:imgBuilding];

        [btnLogin addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchDown];
        [btnLogin setBackgroundColor:[UIColor blackColor]];
        [self.view addSubview:btnLogin];

        tableVw.scrollEnabled=NO;
        tableVw.scrollsToTop=NO;
        tableVw.dataSource=self;
        tableVw.delegate=self;
        [self.view addSubview:tableVw];

    }else{

        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7){

            imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 70, 162, 57)];
            imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(0, 345, 320,140 )];

            btnLogin.frame = CGRectMake(20, 230, 127, 32);

            tableVw=[[UITableView alloc] initWithFrame:CGRectMake(10, 127, 300, 100) style:UITableViewStylePlain];
        }else{

            imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 50, 162, 57)];
            imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(0, 325, 320,140 )];
            btnLogin.frame = CGRectMake(20, 200, 127, 32);

            tableVw=[[UITableView alloc] initWithFrame:CGRectMake(10, 85, 300, 123) style:UITableViewStylePlain];
        }

        imgLogo.image=[UIImage imageNamed:@"icon.png"];
        [self.view addSubview:imgLogo];
        imgBuilding.image=[UIImage imageNamed:@"icon.png"];
        imgBuilding.alpha=0.4;
        [self.view addSubview:imgBuilding];

        [btnLogin addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchDown];
        btnLogin.backgroundColor=[UIColor blackColor];
        [self.view addSubview:btnLogin];

        tableVw.dataSource = self;
        tableVw.delegate = self;
        tableVw.scrollEnabled=NO;
        tableVw.scrollsToTop=NO;
        [self.view addSubview:tableVw];
    }

}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSString *CellIdentifier =[NSString stringWithFormat:@"%D",indexPath.row];

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    cell.textLabel.text=@"1";


    return cell;

}

添加类似btnLogin=[UIButton alloc]init]的语句;高于if。并将类型从roundrect更改为customAnd@user2930730尝试此代码,如果它解决了您的问题,请接受它。所以其他用户可以使用它。@谢谢你的回复,兄弟。非常感谢你。我很乐意帮助你谢谢你@SanketKachhela