iOS 5, Storyboards,ARC: Creating and setting custom delegate and datasource to program. created UITableView

后端 未结 1 1209
时光说笑
时光说笑 2021-01-28 20:24

The prequel of this problem is here.

I am trying to create and set a custom delegate and datasource to my programmatically created UITableView. I\'ve googled around, but

相关标签:
1条回答
  • 2021-01-28 21:07

    I am not sure if you are adding a new UITableView to your current view or not, but I will assume you are doing so.

    If you have a class that conforms to the UITableViewDelegate. But when i needed to create a UITableView programmatically, I create a new UITableView class (with the .h and .m) then make a MutableArray and exposing it as a property to the parent view so it can set the data source.

    From there, you can create an instance of the class along with the datasource (which you exposed from the child object). Finally, you then add the view onto your current view. This method you dont need to set the delegate because your child class conforms to the tableview delegate protocol.

    If you are just modifying the data inside the current tableview then, you use a NSMutableArray and then change the data in it. After then do a

          [self.tableView reloadData];
    

    Hope this helps!

    EDITED

    I might have misunderstood your question, what you (most likely) need to do is create a property of the delegate class then create an instance of your delgate class and assign it to the property.

    Then do a

          [myTableView setDelegate:self.myProperty];
          [myTableView setDatasource:self.myProperty];
    

    This, I believe, would solve you bad access problem.

    EDITED AGAIN

    Create a property inside your .h of the tableview class as such:

        @property (nonatomic, retain) NominalsTableViewDelegate *myDelegate;
    

    From there then inside your .m file, you do something similar to this:

    NominalsTableViewDelegate* delegateClass = [[NominalsTableViewDelegate alloc] init];
    [self setMyDelegate:delegateClass];
    [delegateClass release];
    

    Then you can set your tableview datasource as such:

    [myTableView setDelegate:self.myDelegate];
    [myTableView setDatasource:self.myDelegate];
    

    Note: I currently have no access to a machine to test this, but just something to point you towards.

    0 讨论(0)
提交回复
热议问题