我爲定單地址和發貨地址定製了UITableViewCell(動態創建)。我想獲得UITextField的值。如何在不使用標籤屬性的情況下獲取它的值。以下是我的UITableViewCell - 如何從自定義UItableViewCell獲取UITextfield值。如果UITableviewCell具有多個UITextField而不使用標籤屬性
的cellForRowAtIndexPath代碼原樣
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(isShippingShow){
switch (indexPath.section){
case 0:
{
CardListCell *cell = (CardListCell*)[tableView dequeueReusableCellWithIdentifier:@"CardListCell" forIndexPath:indexPath];
return cell;
}
break;
case 1:
{
NewCardCell *cell = (NewCardCell*)[tableView dequeueReusableCellWithIdentifier:@"NewCardCell" forIndexPath:indexPath];
return cell;
}
break;
case 2:
case 3:
{
PayAddressCell *cell = (PayAddressCell*)[tableView dequeueReusableCellWithIdentifier:@"PayAddressCell" forIndexPath:indexPath];
cell.txtCountry.delegate = self;
cell.txtCountry.inputView = _pickerView;
[self setTextFieldAccessoryView:cell.txtCountry];
return cell;
}
break;
case 4:
{
SettingCell *cell = (SettingCell*)[tableView dequeueReusableCellWithIdentifier:@"SettingCell" forIndexPath:indexPath];
[cell.swSetting addTarget:self action:@selector(changeState:) forControlEvents:UIControlEventValueChanged];
return cell;
}
break;
default:
break;
}
}
else{
switch (indexPath.section){
case 0:{
CardListCell *cell = (CardListCell*)[tableView dequeueReusableCellWithIdentifier:@"CardListCell" forIndexPath:indexPath];
return cell;
}
break;
case 1:{
NewCardCell *cell = (NewCardCell*)[tableView dequeueReusableCellWithIdentifier:@"NewCardCell" forIndexPath:indexPath];
return cell;
}
break;
case 2:
{
PayAddressCell *cell = (PayAddressCell*)[tableView dequeueReusableCellWithIdentifier:@"PayAddressCell" forIndexPath:indexPath];
cell.txtCountry.delegate = self;
cell.txtCountry.inputView = _pickerView;
[self setTextFieldAccessoryView:cell.txtCountry];
return cell;
}
break;
case 3:
{
SettingCell *cell = (SettingCell*)[tableView dequeueReusableCellWithIdentifier:@"SettingCell" forIndexPath:indexPath];
[cell.swSetting addTarget:self action:@selector(changeState:) forControlEvents:UIControlEventValueChanged];
return cell;
}
break;
default:
break;
}
}
return [UITableViewCell new];
}
定製Cell類是原樣
#import <UIKit/UIKit.h>
@interface NewCardCell : UITableViewCell
@property(nonatomic,weak) IBOutlet UITextField *txtCardHolderName;
@property(nonatomic,weak) IBOutlet UITextField *txtCardNumber;
@property(nonatomic,weak) IBOutlet UITextField *txtExpDate;
@property(nonatomic,weak) IBOutlet UITextField *txtCVV;
@end
@interface CardListCell : UITableViewCell
@property(nonatomic,weak) IBOutlet UILabel *lblCount;
@property(nonatomic,weak) IBOutlet UILabel *lblCardNumber;
@property(nonatomic,weak) IBOutlet UIImageView *imgCardIcon;
@property(nonatomic,weak) IBOutlet UIButton *btnSelectCard;
@end
@interface SettingCell : UITableViewCell
@property(nonatomic,weak) IBOutlet UILabel *lblCaption;
@property(nonatomic,weak) IBOutlet UISwitch *swSetting;
@end
@interface PayAddressCell : UITableViewCell
@property(nonatomic,weak) IBOutlet UITextField *txtAddress;
@property(nonatomic,weak) IBOutlet UITextField *txtCity;
@property(nonatomic,weak) IBOutlet UITextField *txtState;
@property(nonatomic,weak) IBOutlet UITextField *txtZipcode;
@property(nonatomic,weak) IBOutlet UITextField *txtCountry;
@end
用你的cellrowatindex tableview委託方法更新你的問題 –
爲什麼你不想要標籤Property?這將很容易獲取uitextfield – ajjjjjjjj
爲什麼不在Scrollview中的文本框? 這會更容易 –