tag:blogger.com,1999:blog-9199573357345606334.post100394964413353683..comments2020-07-31T10:52:03.557-07:00Comments on From a remote village: Organizing a complex UITableView with the iPhone SDK by using a dispatch tablePaul Franceushttp://www.blogger.com/profile/11557290901923425436noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-9199573357345606334.post-63857055914394541232009-08-29T06:20:15.927-07:002009-08-29T06:20:15.927-07:00Thanks Paul.
As I come from a Non Apple world. Pos...Thanks Paul.<br />As I come from a Non Apple world. Posts like yours give me lots of information and motivation.<br />I have just started writing an recipe kind of application where I did not use UITableView. I just used viewcontrollers for each section and each viewcontroller has methods which will create labels(with/without images,checkmarks) as needed and also has property for approximate view size and I add the views from these controllers into the main view using the approximate sizes for size and location of each section. This I know this may be bad but went ahead and wrote as it was for my learning purpose(code snippets below).<br /><br />Then I found your intresting article and from links from your article about multiple lined lables which will make writing this app much more easier. I still have a few questions...<br /><br />If there is no default behaviour which I could have had in the main ViewContoller (NoteViewController)<br />can I just make this a protocol?<br /><br />Also when i wrtie my UITableViewCells for a particular section the content of a cell may be varying a lot like the color from prev cell, height based on text and therefore I dont know from documentation internally how the cells layout can be completely reused but I always see in all code its always dequed and reused by a same named identifier.<br /><br />Sorry for the long post and bad english :-) Also would be great if I can get a skeleton of the main overview classes of your project and if it is okay I will send a request to your mail ID.<br /><br><br />-- Setting a recipe and also finding approximately<br />approximate size of ingredientsview.<br />-(void) setRecipe:(Recipe* ) newRecipe{<br /> <br /> CGSize largeBigSize = CGSizeMake(kMaxWidth-kColumnOffset, kMaxHeight);<br /> CGFloat cHeight;<br /> CGSize ingredientSize; <br /> int ingredientPosition =1;<br /> <br /> <br /> if(newRecipe!=recipe){<br /> [newRecipe retain];<br /> [recipe release];<br /> recipe = newRecipe;<br /> }<br /> <br /> <br /> ingredientSize = [kIngredientHeader sizeWithFont:[UIFont systemFontOfSize:kMainFontSize] <br /> constrainedToSize:largeBigSize<br /> lineBreakMode:UILineBreakModeTailTruncation];<br /> cHeight +=ingredientSize.height+kRowOffset;<br /><br /> NSMutableArray *ingredients = [recipe ingredients];<br /> for (Ingredient *ingredient in ingredients) {<br /> <br /> //NSString *ingredientDescription = [ingredient ingredientDescription];<br /> NSString *ingredientDescription = [NSString stringWithFormat: @"%d. %@",ingredientPosition,[ingredient ingredientDescription]];<br /> <br /> ingredientSize = [ingredientDescription sizeWithFont:[UIFont systemFontOfSize:kSecondaryFontSize] <br /> constrainedToSize:largeBigSize<br /> lineBreakMode:UILineBreakModeTailTruncation];<br /> cHeight +=ingredientSize.height+kRowOffset;<br /> ingredientPosition++;<br /> NSLog( @"Ingredient %@ width: %f height: %f ",[ingredient ingredientDescription],kMaxWidth,cHeight); <br /> <br /> }<br /> <br /> approximateSize = CGSizeMake(kMaxWidth,cHeight);<br /> <br /> <br />}<br /><br /><br /><br />And in viewDidLoad I do this.<br /><br /><br><br /><br />RecipeInstructionsView *instructionsView = [[RecipeInstructionsView alloc]init];<br /> [instructionsView setRecipe:recipe];<br /> [instructionsView setBackgroundColor:[UIColor blackColor]];<br /> CGSize instructionsViewSize = [instructionsView approximateSize];<br /> <br /> [instructionsView setFrame:CGRectMake(0.0, kRecipeCellViewHeight+ingredientsViewSize.height, ingredientsViewSize.width, kRecipeCellViewHeight+ingredientsViewSize.height+instructionsViewSize.height)];<br /> [self.view addSubview:instructionsView];vJnoreply@blogger.comtag:blogger.com,1999:blog-9199573357345606334.post-23547708304353208032009-08-28T15:36:19.341-07:002009-08-28T15:36:19.341-07:00vJ
What to put in the abstract class is up to you...vJ<br /><br />What to put in the abstract class is up to you - whatever makes sense for your implementation.<br /><br />I suggest you read about UITableViews and cells. Generally, you reuse a cell, and just change the content as you go. Typically, the cells in a table view have generally the same layout - perhaps a line of text or two and an image, or some other layout. The only difference is the content. I wouldn't expect that the rows of a table are completely unique. If you happen to have that then you can't use the reusable cell, but if it's just the contents that change but the layout is the same, then you can.Paul Franceushttps://www.blogger.com/profile/11557290901923425436noreply@blogger.comtag:blogger.com,1999:blog-9199573357345606334.post-62068574797236307502009-08-28T11:12:12.048-07:002009-08-28T11:12:12.048-07:00Great Article!!!
I like the way the moduled approa...Great Article!!!<br />I like the way the moduled approach in handling different sections. I am wondering about the default behaviour of the default class and how to implement these. For example should I return a Zero sized UITableCell<br />and also(off Topic) I have a question about reusing the cell. I see evrywhere dequeueReusableCellWithIdentifier but each cell is Unique and how will it get reused.vJnoreply@blogger.comtag:blogger.com,1999:blog-9199573357345606334.post-33826754467149348672009-04-23T09:31:00.000-07:002009-04-23T09:31:00.000-07:00Why not an array? No reason especially, I guess I ...Why not an array? No reason especially, I guess I usually use maps or dictionaries for doing dispatch tables like this, but you are right, in this case an array would work.Paul Franceushttps://www.blogger.com/profile/11557290901923425436noreply@blogger.comtag:blogger.com,1999:blog-9199573357345606334.post-31671318276884092472009-04-23T01:31:00.000-07:002009-04-23T01:31:00.000-07:00It's a nice approach - I'm just wondering why you'...It's a nice approach - I'm just wondering why you're using an NSDictionary thats keyed with an integer - why not just use an array ?<br /><br />If you dynamically removed, say, the table section keyed by '2' then you would have to iterate through the whole dict and readjust the indexes. If you don't do this, you'll get a crash when the delegate is asked to supply the rows for the missing section in the table. <br /><br />If you just used an array, removing an item would automatically shuffle the rest of the elements to fill the gap.Andyhttps://www.blogger.com/profile/07567438754704618031noreply@blogger.comtag:blogger.com,1999:blog-9199573357345606334.post-41201291406164903062009-01-20T10:03:00.000-08:002009-01-20T10:03:00.000-08:00Simply perfect. I used your implementation and now...Simply perfect. I used your implementation and now my 6 section Table is extremely easy to use and extend! Thanks a lot for this great post.urihttps://www.blogger.com/profile/07750525023866521339noreply@blogger.comtag:blogger.com,1999:blog-9199573357345606334.post-70244414364040435542009-01-03T20:39:00.000-08:002009-01-03T20:39:00.000-08:00I'd prefer not to share this with the world. Pleas...I'd prefer not to share this with the world. Please email me and I'll send you a link. You should be able to get email from my profilePaul Franceushttps://www.blogger.com/profile/11557290901923425436noreply@blogger.comtag:blogger.com,1999:blog-9199573357345606334.post-22844476852113001232009-01-03T12:52:00.000-08:002009-01-03T12:52:00.000-08:00I added the class reference to the table view cont...I added the class reference to the table view controller and the abstract class, but it still gives me errors.<BR/><BR/>If you wouldn't mind, it would probably be helpful to see the code (or at least the headers) of the table view controller, the abstract class and the classes that inherit from it.<BR/><BR/>Thanks for all the help.Unknownhttps://www.blogger.com/profile/17729983318582953269noreply@blogger.comtag:blogger.com,1999:blog-9199573357345606334.post-72739867758594999202008-12-31T18:08:00.000-08:002008-12-31T18:08:00.000-08:00Thanks, Sounds like you are making some good exten...Thanks, Sounds like you are making some good extensions.<BR/><BR/>First of all, in the parent class NoteViewController, I put an @class declaration:<BR/><BR/>#import <UIKit/UIKit.h><BR/>#import <AddressBook/AddressBook.h><BR/>#import "NoteList.h"<BR/>#import "Note.h"<BR/>#import "PixieNetNodeDescriptor.h"<BR/><BR/>@class AbstractNoteSectionController;<BR/><BR/>@interface NoteViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UIActionSheetDelegate> {<BR/> <BR/><BR/>That prevents the circular reference. If that doesn't solve the problem for you let me know and I'll try to post the code somewhere.Paul Franceushttps://www.blogger.com/profile/11557290901923425436noreply@blogger.comtag:blogger.com,1999:blog-9199573357345606334.post-64685634987939122912008-12-31T16:24:00.000-08:002008-12-31T16:24:00.000-08:00First, great article. I am using this as the basi...First, great article. I am using this as the basis to create a mutable array of table sections. This will allow me to remove particular sections based on state (for example a basic vs. advanced version) and have the table redraw with only the visible sections.<BR/><BR/>Also, I can use the order of the array to dictate the section order rather than have it as part of the abstract class.<BR/><BR/>I am having an issue when including the parent though...<BR/><BR/>If I just send in the UITableView when initializing the section class it works fine, but once I try to include the controller (as you have for your parent) I get errors that say the following:<BR/><BR/>error: cannot find interface declaration for 'Abstract...', super class of '...TableSectionController'<BR/><BR/>There is an error for every sub class of the abstract class I have and it shows up right below the .h reference in the .m for each subclass... :-S<BR/><BR/>Would it be possible for you to post your code so I can see if I am just making a stupid mistake? <BR/><BR/>I am trying to narrow down why this is happening and it may be circular references or something else, but it is not easy to tell at this time...<BR/><BR/>Thanks in advance.Unknownhttps://www.blogger.com/profile/17729983318582953269noreply@blogger.com