M
M
mozilla92013-12-14 06:17:36
Objective-C
mozilla9, 2013-12-14 06:17:36

What are the best practices for iPhone projects?

I have been developing for ios for 3+ months. Prior to this development in Java.
During these months, a feeling of discomfort has formed - I'm doing something wrong, I can't find the right approach to development. This is code reuse, a storyboard - code connection, the use of notifications. I will describe my feelings-approaches. What follows is a bit confusing.
1) Dependence on the storyboard, manual setting of the properties of UI elements. If two similar screens - then double work, etc.
How I try to decide:
- if the screen is not the simplest (view + a couple of buttons) and allows ui, then I try to do it on the table.
Attracts the following: Reuse of cells - I put down the class, throw and connect elements, I take out all customization in methods for initialization.
If you need to resize, hide something (animation), work with the keyboard (even if it is mostly static information), then the table has everything - deleting or adding cells without calculating new origins and sizings, scrolling to the desired cells when working with the keyboard , footers.
Using a UIScrollView causes rejection after one screen that had a UIScrollView and several nested UIViews that needed to be hidden-showed with animation (calculating new origin-sizings took a lot of time).
2) Using notification [NSNotificationCenter defaultCenter] for communication between screens (sending some events).
How justified is this? If, in a good way, you need to use the delegate pattern, but you have to pass the link to the delegate to the desired screen along the chain of screens, or the desired screen lies in the array of the navigation controller.
A project colleague in such cases uses notifications. I'm annoying in this code noodles. Before closing, the screen sends a notification somewhere, and in order to understand the logic, you need to look for screens that are subscribed to these notifications.
3) Organization of the project
- is it normal if related files, like in java, are allocated in separate directories. Or just create virtual directories (refs) in x-code, but really put all the files in one folder.
- naming controller classes. ContactsEditorViewController vs ContactsEditor.
4) Localization
- there is a feeling that NSLocalizedString is the most correct method for localization. I tried localization through the storyboard... but something is not right.
In general, after Java, there is a feeling that there is a lot of manual labor in development for ios.
Please advise how it can be reduced.
How to better organize the structure of the project.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
An, 2013-12-16
@Flanker_4

1) This topic has already been discussed. I think that the complete rejection of the story board is stupidity. A storyboard makes life a lot easier when designing interfaces, especially when you support the full range of devices (retina/non-retina, ios 6/7, ipad/iphone/iphone 4").
For example, you have a button that repeats on a bunch of screens. You declare the XXXButton class inherited from UIButton and implement the
-(void) setupButton method in it, where you write all the necessary changes (font, color, background) using the same code
. it has a setupButton method.In the
storyboarde, add a regular button, but change its type from UIButton to XXXButton.Similarly for other UI elements.You get a kind of crooked analogue of css + html.
There is also the option of moving the button to a separate xib and loading it from there. But this can greatly degrade performance.
Well, yes, sometimes the use of storyboards is really not justified ...
As for the table, Apple likes to redo a lot in new versions of the firmware, and those crutches that you used to achieve the layout you need can suddenly break. After all, UITableView is designed for lists.
2) stackoverflow.com/questions/5210535/passing-data-b... . Look towards the end of the answer marked as correct. NotificationCenter is not the best solution. Moreover, by sending a notification, you cannot be sure that someone will receive it at all. But you never know what is on the other end of the wire, and if the recipient of the ViewController has not yet been created at the time of sending the notification?
3)

- is it normal if related files are allocated in separate directories as in java. Or just create virtual directories (refs) in x-code, but really put all the files in one folder.
I think the first option is better. Because you can interact with the project not only through xcode
It's better to specify that this is a specific ViewController , and yes, don't forget the . I also highly recommend checking out developer.apple.com . There are several articles on naming conventions for classes, methods, and the like. Some features without the "correct" names can break (kvo , arc)
And you can always read recommendations from the same Google...
4) Localization
These are different tools for different purposes. NSLocalizedString is used when you need to translate interface text. Storyboard localize - when you need to redesign the interface. To make it clearer for you, imagine that an application is being made that is focused only on a Western user. NSLocalizedString is enough, there was a Home button, now it's Home :).
But if you want to sell the application somewhere in the east, then it turns out that there are hieroglyphs, writing from right to left / top to bottom. And in general, they don’t know how to think in a square-nest way, give them a completely different interface .

A
Alexander, 2013-12-15
@alexyat

1 We need to abandon the storyboard, it was made for designers-programmers, IMHO. Usually, the project is stylistically the same, the input fields are the same, the buttons are the same, only the positions differ, and all sorts of little things. In such cases, I create a class with static methods, to which you pass CGRect and NSString, and they give you a button or label, for example.
2 Notification is usually used when it is necessary to notify several classes, for example, about data loading. For the rest, there is a delegate and a singleton
3 Here, as you like, I put everything in directories and create refs with the same names. I name it like this - RootVC, UserView, UserItem
4 Having abandoned the storyboard, I use only NSLocalizedString

M
mozilla9, 2013-12-15
@mozilla9

Those. only create a controller in the storyboard - bind the main components (table or scrollview) and then add other components in the code?
After all, you can’t get away from the storyboard at all? Put down outlets and the like.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question