从视图控制器

时间:2015-04-22 09:22:09

标签: ios objective-c cocoa-touch uiviewcontroller

我有2个视图控制器, 我想在它们之间传递数据,在第一个视图控制器中我使用此方法切换到其他视图控制器并传递数据:

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
                            user:(id<FBGraphUser>)user {

    NSString *userName = [user username];
    NSString *userId = [user id];

    dashBoardViewController *dashBoardViewController =     [self.storyboard instantiateViewControllerWithIdentifier:@"dashBoardViewController"];
    dashBoardViewController.first_name = userName;
    dashBoardViewController.id = userId;
    [self presentModalViewController:dashBoardViewController animated:YES];
}

在视图controller.h上有这个。

@interface ViewController : UIViewController <FBLoginViewDelegate>

@property (weak, nonatomic) IBOutlet FBLoginView *loginButton;

@property (weak, nonatomic) IBOutlet UIButton *showEvent;

@property (weak, nonatomic) IBOutlet UIButton *goQrcode;

@property (retain, nonatomic) NSString *id;

@property (retain, nonatomic) NSString *first_name;

在第二个视图控制器中我有这个方法来读取变量并切换到另一个视图控制器:

- (IBAction)gotoEvents:(id)sender {

    events *events;
    events.first_name = _first_name;
    events.userid = _id;
    [self.storyboard instantiateViewControllerWithIdentifier:@"events"];
    [self presentModalViewController:events animated:YES];
}

这是我的头文件:

@property (nonatomic, retain) NSString *first_name;
@property (nonatomic, retain) NSString *id;

- (IBAction)gotoEvents:(id)sender;
它说我 property&#39; first_name&#39;没有在类型&#39;事件&#39;

的对象上找到

1 个答案:

答案 0 :(得分:0)

试试这个,

 public void dbConnect()
    {
        using (SqlConnection myConnection = new SqlConnection("server=CHAYU\\SQLEXPRESS;" +
                                   "Trusted_Connection=yes;" +
                                   "database=restaurantApp; " +
                                   "connection timeout=30"))
        {

            string oString = "Select * from Meal where availability=1";
            SqlCommand oCmd = new SqlCommand(oString, myConnection);
            myConnection.Open();
            using (SqlDataReader oReader = oCmd.ExecuteReader())
            {
                while (oReader.Read())
                {
                    Meal m = new Meal();
                    m.mealID = Convert.ToInt32(oReader["mealId"]);
                    m.mealName = oReader["mealName"].ToString();
                    m.quantity=Convert.ToInt32(oReader["quantity"]);
                    m.timeToProduce = Convert.ToInt32(oReader["timeToProduce"]);
                    m.availability = true;


                }

                myConnection.Close();
            }
        }
    }

events *events = [self.storyboard instantiateViewControllerWithIdentifier:@"events"]; events.first_name = _first_name; //class name Should Start With capital letter and should use camel case for naming. 应命名为events,因为它的类名称为