Duplicate the UIButton and Move it
2015-01-30 13:56
155 查看
http://stackoverflow.com/questions/19241208/duplicate-the-uibutton-and-move-it/26438692#26438692
1down votefavorite | I have one UIButton(lets say instance1).I have set target method when it moves.So when I try to move(drag) I want to do that create copy of instance1and that copy button should be moved(dragged).Yes I know that -copy will not support to UIButton.So I used : NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject: sender]; UIButton *buttonCopy = [NSKeyedUnarchiver unarchiveObjectWithData: archivedData]; But the problem is when I am trying to move copy button,its not moving and on second attempt it is hiding/removing from screen.Please help me. ios objective-c uibutton nsdata
| ||||||||||||||||||||
|
1 Answer 1
activeoldestvotesup vote0down vote | Your example button is self.exampleButton...-(UIButton*)_copie { NSData *arch = [NSKeyedArchiver archivedDataWithRootObject: self.exampleButton]; UIButton *nu = [NSKeyedUnarchiver unarchiveObjectWithData: arch]; [self.view addSubview:nu]; nu.frame = self.exampleButton.frame; [nu addTarget:self action:@selector(oneLinkClicked:) forControlEvents:UIControlEventTouchUpInside]; return nu; } here's an example of making a number of the buttons, in a vertical column. in the example the data comes from a Dictionary... CGPoint zero = self.exampleButton.center; CGFloat gap = self.exampleButton.bounds.size.height * 1.25; NSInteger kount=0; self.orderedLinks = [[NSMutableArray alloc] init]; for ( NSDictionary *link in self.arrayOfLinks ) { NSLog( @"one title... %@", link[@"title"] ); NSLog( @"one url... %@", link[@"url"] ); UIButton *copy = [self _copie]; CGPoint newpos = zero; newpos.y = newpos.y + ( kount * gap ); copy.center = newpos; [copy setTitle:link[@"title"] forState:UIControlStateNormal]; copy.tag = kount; [self.orderedLinks addObject:link[@"url"]]; kount++; } [self.exampleButton removeFromSuperview]; and when a button is clicked... -(IBAction)oneLinkClicked:(UIButton *)sender { NSLog(@"this tag clicked ...... %ld", (long)sender.tag); NSString *goUrl = self.orderedLinks[ sender.tag ]; NSLog(@"goUrl ...... %@", goUrl ); }
|
相关文章推荐
- “App” is damaged and can’t be opened. You should move it to the Trash.
- It obviously could not tell the difference between Indian music and jazz
- With Fear and Wonder in Its Wake, Sputnik Lifted Us Into the Future
- I took time for preliminary study of the lua and php, it's too difficlt to squeeze time for me
- Understanding the SharePoint calendar and how to export it to iCal format
- it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element
- It`s Both What You Say and the Way You Say It.(你说什么与你怎么说同样重要)
- Matrix and linear algebra in F#, Part IV: profile your program, find the bottleneck and speed it up: using matrix multiplication as an example[z]
- cvs update: move away src *****; it is in the way
- On the Way to the Web: The Secret History of the Internet and Its Founders
- The database has local access protection and you are not authorized to access it locally
- The Xen Hypervisor and its IO Subsystem
- Binding the Enum to the Dropdown Listbox and Sorting it on Values.
- Issue 12(Anyone can make things bigger and more complex. What require more effort and courage is to move in the opposite directi
- add cool toolbar 256corler is easy,only two file and onCreate func is needed also the MainFrame.toolbar must resize to what real need and also the load width is same to it.
- Noticed a strange thing the other day, a list has the property ItemCount and also an Items collection which has its own .Count b
- Project Management Nation : Goals for the New and Practicing IT Project Manager
- The IT Professional's Business and Communications Guide: A Real-World Approach to CompTIA A+ Soft Sk
- Ontology ---------- the definition of philosophy and in IT field
- It will cause a new session when you use lazy loading collection, and the collection will assicated with the new session and the