473,287 Members | 1,865 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,287 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 5902
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 ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

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.