gpt4 book ai didi

objective-c - TableView Controller 和 ModalView 中的 TextField

转载 作者:行者123 更新时间:2023-11-29 13:41:53 25 4
gpt4 key购买 nike

我尝试在 ModalView 中添加 tableView 和 TextField。我这样做。我创建了新的 View Controller 并为它提供了

#import <UIKit/UIKit.h>


@protocol UYLModalViewControllerDelegate

-(void) buttonDonePassed :(NSArray *) variables;

@end

@interface UYLModalViewController : UIViewController <UITableViewDelegate>
{

id<UYLModalViewControllerDelegate> delegate;

IBOutlet UITableView *tblView;
IBOutlet UITextField *textField;

NSMutableArray *cellsArray;
//UITextField *textField;



}
@property (nonatomic, assign) id<UYLModalViewControllerDelegate> delegate;
@property (nonatomic, retain) IBOutlet UITableView *tblView;
@property (retain, nonatomic) IBOutlet UITextField *textField;


@end

然后在 .m 文件中创建函数

#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [cellsArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

cell.textLabel.text = [cellsArray objectAtIndex:indexPath.row];
// Configure the cell.

return cell;
}

和ViewDidiLoad

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(buttonPassed:)];

//UITableView *tableView = [[UITableView alloc] init];
//[self]
cellsArray = [[NSMutableArray alloc] initWithObjects:@"one",@"two",@"three", nil];
[tblView reloadData];
}

但是我的程序没有去到TableViewDelegate方法(比如cellforrowAtIndexPath)

最佳答案

您需要将UYLModalViewController 设置为tableViewdelegatedatasource


看起来您正在使用 Interface Builder,因此您需要:

  1. control + click tableView 并将其拖到 File's Owner
  2. 然后从 HUD 菜单中选择 datasource
  3. 然后重复该过程,但选择delegate

注意
你的 Controller 也应该符合 UITableViewDatasource 给你:

@interface UYLModalViewController : UIViewController <UITableViewDelegate, UITableViewDatasource>

1.

enter image description here

2.

enter image description here


如果您愿意,可以在 viewDidLoad 中的代码中执行此操作,或者如果您以编程方式执行此操作,则可以在创建 tableView 的任何地方执行此操作。

self.tableView.delegate   = self;
self.tableView.datasource = self;

关于objective-c - TableView Controller 和 ModalView 中的 TextField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8866949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com