473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

SWIFT: Trigger function from TableCell

116 64KB
Hi.

I have a ViewController, say HomeView.
It contains a TableView, say MyTable.
The table has a custom cell of class MyCell.

How can I assign delegates, protocol or whatever is needed to get a button click (addTarget method) within MyCell to trigger a function in main ViewController, HomeView?

I can't seem to use self, ParentViewController, HomeView() to get error free code.

I did manage to get the iOS Simulator to work by using 'HomeView()' instead of 'self' in the addTarget but the actual device doesn't seem to like that at all.

Thanks.
Feb 7 '16 #1
1 5953
robertybob
116 64KB
I solved this using NSNotificationCenter - not sure that this is really the best method but anything that works when it comes to Swift is ok with me.

Main Controller

Added the following to the ViewDidLoad where 'addButtonPressed' deals with the processing
Expand|Select|Wrap|Line Numbers
  1. NSNotificationCenter.defaultCenter().addObserver(self, selector: "addButtonPressed", name: "addToList", object: nil)
  2.  

Custom Cell

For the custom cell I needed to call a function there using the following.
Expand|Select|Wrap|Line Numbers
  1. addToListButton.addTarget(self, action: "addListPressed", forControlEvents: .TouchUpInside)
  2.  
The function 'addListPressed' then has the following code to report back to the parent controller to complete the action where 'myListButton' is a global variable storing the button pressed.
Expand|Select|Wrap|Line Numbers
  1. func addListPressed(sender:UIButton) {
  2.         myListButton = sender
  3.         NSNotificationCenter.defaultCenter().postNotificationName("addToList", object: nil)
  4.  }
  5.  
Hope this can help someone save some time and effort even if not a perfect solution.
Feb 9 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Steven Wu | last post by:
------=_NextPart_000_0168_01C35D9A.B3ECE760 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi: It seems to me that there is no trigger function in...
2
by: Jules Alberts | last post by:
Hello everyone, Several columns in sereval tables in my DB should always be lowercase. I now have a simple function: create or replace function code_lower() returns trigger as ' begin...
0
by: Rajat Katyal | last post by:
----- Original Message ----- From: Rajat Katyal To: pgsql-jdbc@postgresql.org Sent: Saturday, January 31, 2004 10:15 AM Subject: Trigger function aborts the transaction on exception Hi:...
2
by: Karl O. Pinc | last post by:
I'm sure I saw something like this on the postgresql web site but the the search function is down in the documentation area. I'm unable to pass a function arguments in a CREATE TRIGGER...
5
by: Peter Erickson | last post by:
I am running postgresql 7.4.2 and having problems creating a trigger function properly. I keep getting the following error: ERROR: OLD used in query that is not in rule I have a table called...
0
by: Dennis Gearon | last post by:
If I have the following table: create table my_table( start TIME, end TIME ); and then I wanted a function as a trigger that would compare any INSERTS or UPDATES to see if there was any...
2
by: Reshmi Jacob | last post by:
Hello, Can any one help me in creating a trigger to update system date into a table while inserting a record into that table. I tried it like this, it is showing error !!! The following error...
1
by: djdevx | last post by:
Dear all PostgreSQL xperts! Hi, I am newbie in PostgreSQL. I am currently developing an app that use PostgreSQL as a BackEnd Database. Now I am having problem with the function trigger since last...
2
by: whsdu | last post by:
This is a really simple question and I'v been working on it for 2 hours........ The table is: CREATE TABLE download ( id integer NOT NULL DEFAULT nextval('seq'::regclass), songid integer...
1
by: rubi tiwari | last post by:
Hey am usng swift mail function for sending a mail in php and its properly in working in localhost i using wamp server but when my software is online then it not working mail not to in working ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.