cuốn sách gpt4 ai đã làm

ios - 将参数从一个 xib 传递到另一个 xib

In lại Tác giả: Walker 123 更新时间:2023-11-28 21:52:45 26 4
mua khóa gpt4 Nike

我的第二个 View Controller 中有标签。我想将按钮索引从 firstviewcontroller 传递到 secondviewcontroller 标签。当我按下按钮时,它转到第二个 View Controller 但标签为零

//FirstViewController.m

NSInteger index = [carousel indexOfItemViewOrSubview:sender];
int ind=index;
SecondViewController *sVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:[NSBundle mainBundle]];
sVC.myLabel.text=[NSString stringWithFormat:@"%d",ind];
[self presentModalViewController:sVC animated:YES];

//SecondViewController.h

@property (strong, nonatomic) IBOutlet UILabel *myLabel;

//SecondViewController.m

@synthesize myLabel;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSLog(@"%@",myLabel.text);

}

câu trả lời hay nhất

在 SecondViewController.h 中添加另一个属性:

@property (nonatomic) NSInteger index;

然后在 FirstViewController.m 中将 index 的值传递给第二个 View 的索引:

NSInteger index = [carousel indexOfItemViewOrSubview:sender];
int ind=index; //now you don't need this

SecondViewController *sVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:[NSBundle mainBundle]];
sVC.myLabel.text=[NSString stringWithFormat:@"%d",ind];

// New line
sVC.index = index;

[self presentModalViewController:sVC animated:YES];

关于ios - 将参数从一个 xib 传递到另一个 xib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27709436/

26 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress