简体   繁体   中英

using viewWithTag for a view inside a cell that's inside a tableview

This is my layout: I have a TableView -> Cell - > Inside the cell I have some UITextField s and a UIView with a few more UITextField s. When I want to fill them with data inside cellForRowAtIndexPath I've created a simple for loop to fill them all. My problem is that I can't access the UITextField inside the separate UIView using viewWithTag (I don't want to assign each and every one of them by their outlet name, that's why I'm using the for loop).

So this code will only work on the UITextField s that are inside the cell but not on the UITextField s that are inside the view that is inside the cell:

for (int i=1;i<15;i++)
{
    UITextField *temp = (UITextField *)[self.view viewWithTag:i];
    temp.text = @"something";
}

Another thing that I don't understand is that if I log the UITextField I can see that it's filled with data but I don't see it on screen.

        UITextField *temp = (UITextField *)[self.view viewWithTag:8]; //8 is a tag for a `UITexiField inside the view that is in the cell 
        NSLog(@"temp: %@",temp);
        temp.text = @"something";
        NSLog(@"temp: %@",temp);

baseClass = UITextField; frame = (0 12; 35 35); text = ''; clipsToBounds = YES; autoresize = RM+BM; tag = 8; gestureRecognizers = <NSArray: 0x7578650>; layer = <CALayer: 0x7577650>>

baseClass = UITextField; frame = (0 12; 35 35); text = 'something'; clipsToBounds = YES; autoresize = RM+BM; tag = 8; gestureRecognizers = <NSArray: 0x7578650>; layer = <CALayer: 0x7577650>>

But I won't see it on screen.

  1. After you assign temp , then you have to iterate through the view UITextField and UIView in temp to get through what you want.

  2. Are you adding them as a subview ? Normally that is why they don't show up even thought he content is there as below:

     [self.view addSubview:temp]; 

Download the category available here

Use the method

- (NSArray *)viewsWithTag:(NSInteger)tag;

Make sure u have the same tag number for all the text field as the method returns array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM