Wednesday, May 16, 2012

How to let user change iphone app theme?

I have Article and Category entities that have a many to many relationship. Category has a name and a imagePath (which keep its name and path to image of an icon for that category).
If I want to let user change icons (for example change theme with a new pack of icon) what should I do?



What I'm thinking now is create separate entity, called Theme, which keep categoryId (need to add that to category) and move imagePath from Category to this Theme entity, so it would become



Article <<->> Category  
..... - categoryId
..... - name


and



Theme
-categoryId
-imagePath


with this approach I have to keep the selected Theme in NSUserDefault and lookup with categoryId every time I need an image.



Any thing I should concern with this or there is a better way of doing this kind of thing?



Edited



I will let user choose theme and save it in NSUserDefaults (just like normal setting preference), then when I want to show it for Article I get categoryId from Category and use that categoryId to search in Theme entity, get the imagePath and load image from that path. Here is some NSPredicate I think of



NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Theme" inManagedObjectContext:moc];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDescription];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"categoryId == %@ AND themeId = %@", category_id_for_article, theme_id_from_user_defaults];
[request setPredicate:predicate];




No comments:

Post a Comment