How to Get the value(label) from the TextField ins

2020-05-09 22:55发布

问题:

I want my iOS app to pass to a URL the text the user types. The relevant code is pasted below. WHen I run the app, the text does not get assigned any value. It stays as null.

I am new to iOS programming and am probably missing something obvious here. Any help/pointers will be appreciated.

Mac OS version : 10.6.8 (64 bit) Xcode version : 3.2.3

In the snapshop.. "I have created a Table View and placed custom cell inside each row of a table. TextField is inside the custom cell view. Post is a button next to the textField which is a done Button. If I click that button, the text we are entering in the textField should post on URL which i have specified in my code snippet."

NOTE: The text is like a comment and posting this comment that should post on particular image in that cell.

I have copied the code snippet below. I have also attached an image to explain.

-(IBAction)postAction:(id)sender

{

    int index=[sender tag];

    homecell *cell = [[homecell alloc] init];

    UITextField *txt_c =(UITextField *)[cell.txt_comment viewWithTag:index];

    NSLog(@"jj %@",txt_c);

    gen_data *ut1=[[gen_data alloc]init];

    gen_data *ut=[gen_data getInstance];

}

回答1:

I assume that you have created that view using the interface builder, probably all you need is to connect that textfield as an IBOutlet and access the value.

IBOutlet is the key word here, search for it and you will find really fast the way to do it.

Check this link.



回答2:

You should get some basics of iOS programming first.

Why are you creating a totally new custom cell that is irrelevant to your UITableView? When you create it that way, it's a totally new UITableViewCell. You should connect it to it first, get its NSIndexPath and then operate with it and do what you want.

BTW, if you want to see the text of UITextfield you should NSLog myTextField.text

And you could easily write viewWithTag:sender.tag, no need to create an extra ivar here