slackhq / SlackTextViewController

⛔️**DEPRECATED** ⛔️ A drop-in UIViewController subclass with a growing text input view and other useful messaging features
https://slack.com/
MIT License
8.32k stars 1.08k forks source link

how to separate the UITableViewDelegate and UITableViewDataSource and use external table view? #40

Closed lukewcn closed 10 years ago

lukewcn commented 10 years ago

I already have a table view in the controller, and the controller conforms the UITableViewDelegate and I have another datasource file conforms the UITableViewDataSource, how can i handle this situation?

dzenbot commented 10 years ago

I guess you can simply instantiate your custom classes, keeping a strong reference to them in your SlackTextViewController subclass, and override the tableview's delegate/datasource.

self.tableView.delegate = myCustomDelegateObject;
self.tableView.dataSource = myCustomDataSourceObject;

Does this make sense?

lukewcn commented 10 years ago

Did not figure it out, I just not get your meanings. Do you mean, make my custom controller subclass the SlackTextViewController, and keep my tableview and change the delegates?

lukewcn commented 10 years ago

I mean a tableview created by xib, I found #16 , but seems no good solution for this, did you make any change for #16 ?

dzenbot commented 10 years ago

Sorry, I'm not really understanding what you are asking... You want to use a custom tableview? or delegate/datasource?

lukewcn commented 10 years ago

I use storyboard to create tableView, my question is just like the #16

mcgraw commented 10 years ago

@hit1983 I think what you're asking is how to connect a tableview you've already added to your storyboard via an IBOutlet?

Right now you'll want to let the SlackTextViewController create that for you so it can create it & properly set up the constraints. In order to tell slack what you want you'll use the default table view style. You can override this if needed.

+ (UITableViewStyle)tableViewStyleForCoder:(NSCoder *)decoder
{
    return UITableViewStylePlain;
}

From there you'll just override the delegate methods in your custom controller or set the delegate & dataSource to another class. Check out the example project.

You might be asking, 'well how do I have other things in the view beside the table view?' I believe the current intent behind this implementation is to have the entire view own the tableview or collectionview in order to properly handle scrolling & moving the text field.

dzenbot commented 10 years ago

Well said @mcgraw! Closing this for now.