Pregunta

Iam starting off on my first project using cocoa and was hoping you could give me some advice. What I want to achieve is quite simple. All I want is a simple message box may be using NSView that will display messages. The messages are simply text stored in may be array or queue. Lets assume there are 5 text messages in queue "Hi", "Hello", "What", 'How", "Where". I would want my view to display "Hello" first and provide two navigators using "< >" on either side of the message box. When the user clicks ">" I display "What" and when your clicks "<" I display "Hi". Can someone give me pointers to help achieve this? Also any sample code for the same would be helpful. Thanks.

Regards, Chands

¿Fue útil?

Solución

make array with that 5 strings . take one label do not forget to connect it(IBOutlet not IBAction). then take 2 buttons one for increment and one for decrement connect them too in interface builder(IBAction method not IBOutlet). now you have 2 methods for next button and previous button. in next button method increment objectAtIndex of array by 1 and in previous button method decrease ObjectAtindex by 1. show the current index on label

Note: put if condition in increment like if its not exceeding [array count] and in decrement it should not exceed 0

you can make custom button like this

    UIButton *Button = [UIButton buttonWithType:UIButtonTypeCustom];  

perform method like this on button

     [Button addTarget:self action:@selector(YourMethod) forControlEvents:UIControlEventTouchUpInside];

then add this button to your view [YourViewName addSubview:Button]; yes you need to set frame where you want to put this button in view

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top