UI parts may or may not be displayed.

Asked 1 years ago, Updated 1 years ago, 73 views

I am using objective-c.FirstViewController performs parse signup and then transitions to secondVC.The secondVC includes label, button, tableView, and imageView.TableView and imageView are drawn every time, but label and button are often not drawn.Why?

--- FirstViewController ---

-(void)moveToSecontVC{
PFUser* user = PFUser currentUser;
NSError* error=nil;
user signUp:&error;
if(!error){
    SecondViewController*SecondVC = [[SecondViewController alloc] init];
    [self presentViewController:createProfileVC animated:YES completion:nil];
    }
}

--- SecondViewController ---

-(void)viewDidLoad{
superviewDidLoad;

UILabel* label = [[UILabel alloc] initWithFrame: CGRectMake(30,80,260,0)];
label.textAlignment=NSTextAlignmentCenter;
label.textColor=[UIColor whiteColor];
label.text=@"text";
self.view addSubview:label;


UITableView*tableView=[[UITableView alloc] initWithFrame: CGRectMake(0,200,self.view.frame.size.width,88)];
tableView.delegate=self;
tableView.dataSource=self;
tableView.allowsSelection=NO;
tableView.scrollEnabled = NO;
[self.view addSubview:tableView];

UIButton*button=[[UIButton alloc] initWithFrame: CGRectMake(30,296,260,60)];
button addTarget:selfaction:@selector(pushedContinue) forControlEvents:UIControlEventTouchUpInside;
[Button setImage: UIImage imageNamed:@"button"] forState:UIControlStateNormal;
self.view addSubview:button;

UIImageView* imageView=[[UIImageView alloc] initWithFrame: CGRectMake (115, 90, 90, 90)];    
imageView.image=[UIImage imageNamed:@"image"];
[self.view addSubview: imageView];

}

---add ---
When I checked the recursiveDescription, it seemed that addSubView was done.Also, when I tap where button should be, button is now visible.

ios objective-c

2022-09-30 20:54

1 Answers

UILabel*label=[UILabel alloc] initWithFrame: CGRectMake(30,80,260,0)];

The height of the label is 0.I can't see it as it is.

For button, you may have failed to retrieve an image from a resource.What happens if I use text instead of images?

UIButton*button=[[UIButton alloc] initWithFrame: CGRectMake(30,296,260,60)];
[Button setTitle: @ "Button" forState: UIControlStateNormal];


2022-09-30 20:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.