单击按钮时在另一个视图控制器上显示图像

时间:2016-08-25 10:06:03

标签: ios swift uiviewcontroller uicollectionview uistoryboard

3 buttons view controllercollection view view controller images。我想在collection view上显示与button clicked对应的相应library(RgoogleMaps) library(maps) library(ggmap) library(ggplot) STRTRADECODE <- c("London","Sheffield","Glasgow") StoreLocations <- as.data.frame(STRTRADECODE,stringsAsFactors=F) StoreLocations %>% mutate_geocode(STRTRADECODE) %>% rename(longitude = lon,latitude=lat) -> StoreLocations CustomerLocations <- StoreLocations CustomerLocations$longitude <- CustomerLocations$longitude - 1 UKMap <- qmap("United Kingdom", zoom = 6.0) UKMap + geom_point(mapping=aes(x = longitude, y = latitude), data = StoreLocations, colour = "red" ) + geom_text( mapping=aes(x = longitude, y = latitude, label = STRTRADECODE ), data= StoreLocations, nudge_x = 0.8 ) + geom_point(aes(x = longitude, y = latitude ), data = CustomerLocations, colour = "green" ) 。我有按钮A,B,C等,如果单击按钮A,则在另一个视图控制器上显示图像A1到A4,依此类推。我是新手,如果你能告诉我是否有办法,我会很高兴。

2 个答案:

答案 0 :(得分:0)

  

Swift 4

首先,在每个按钮操作中添加通知:

 NotificationCenter.default.addObserver(self, selector: #selector(self.YourFunctionName), name: Notification.Name("buttonAIsPressed"), object: nil)

现在在集合视图类的viewDidLoad中添加一个通知侦听器,并在选择器中调用该函数:

{{1}}

现在无论何时按下按钮,都会调用您命名的函数。

答案 1 :(得分:-2)

您需要使用闭包或全局观察者。

在视图中加载

 routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Promotion", id = UrlParameter.Optional }, // changed to Promotion
                new[] { "Nop.Web.Controllers" }
            );

发送功能

weekCalendar.calendarclosure = { (calendar) in 
code
}